3.4. 添加逻辑 Adding Logic - Origami Studio教程


下载教程文件** ·····密码: ahgt**

选择对应名称的文件夹下载,内包含一个(开始)和一个(已完成)文件;(开始)文件用来和教程同步操作,(已完成)是最终结果。


Add logic to your transitions and flows.给过渡和流程添加逻辑。

Often when prototyping, we want interactions to only occur sometimes — when something is true or false, or to let multiple things control an interaction, such as two different buttons having the same effect.

有时候我们希望原型上的交互只在特定的的情况下发生 - 当布尔值为真或假时,或者让多个事物控制一个交互,比如两个不同的按钮具有相同的效果。

This is called adding logic, and we're going to learn how do this in Origami by building an Instagram Direct Messages prototype.

这种行为称为添加逻辑,我们将通过构建一个《Instagram 直接发送消息》原型来学习如何在Origami 中添加逻辑。

Know some code? 需要懂代码吗?

If you're coming from a code-based background, such as JavaScript or Framer (CoffeeScript), Origami might be a bit different than you are used to. We recommend that you visit Coming From Code before continuing.

如果会程序语言,如JavaScript、Framer (CoffeeScript) ,Origami 可能跟它们有些不一样。建议先阅读《Coming From Code 来自代码》

Setting up 配置

You should notice when you open the file that some core interactions have already been created.

你应该注意打开文件时,已经创建了一些核心交互。

Your starting tutorial file should look similar to this. 起始教程文件应与此类似。

The basis of this prototype is centered around the direct messaging functionality found in Instagram. We have our Send To layer, which opens the Direct Messages Modal Group, and the Cancel layer which in turn closes it.

这个原型的基础是以Instagram的直接发送消息功能为中心。
我们有 Send To 按钮用来打开了 Modal 图层组 ,Cancel 图层用于关闭 Modal 。

On closer inspection, our prototype contains the Direct Messages Hit Area. Interacting with this layer causes the [Switch] to Turn On, and tapping on the Cancel layer causes the Switch to Turn Off.

原型包含 Direct Messages Hit Area,这个图层用来交互并连接到 Switch 模块的 Tun On 接口,点击 Cancel 图层激活 Switch 模块的 Turn Off 接口。

Or 或

Ideally a Tap on Color Fill would also close Modal. Hover over Color Fill in the Layers panel and click Tap under the Touch menu.

理想情况下,点击 Color Fill (等于空白区域)也将关闭 Set to 图层。将鼠标悬停在 “Color Fill” 图层上,然后单击 “Touch” 菜单下的“Tap”。

A new Interaction patch should appear on the Patch Editor.

模块编辑器中出现了一个新的 Interaction 模块。

In the Viewer, try opening Modal and then tapping on Color Fill. Looking at our new Interaction patch we can see see that our tapping is detected.

在查看器中点 Color Fill 图层,可以看到新加的 Interaction 模块已经被监听了。

Keep an eye on the Down and Tap outputs of the Interaction patch whilst interacting with Color Fill. 盯着 Interaction 模块的 Down 和 Tap 输出口点击 Color Fill 图层。

We ultimately would like tapping on Cancel or Color Fill to Turn Off the Switch. We need an Or patch to allow both of these options.

最终想要点击 Cancer 或 Color Fill 关闭开关。
我们需要一个 Or 模块来允许这两个选项。

Double-click on the Patch Editor Cmd Return and add an Or patch. Connect the Tap output from the Cancel Interaction patch to an input of Or. Also connect the Tap output of Color Fill to the remaining Or input.

添加模块 Or Shift O。将 Cancel 图层的 Interaction 模块 Tap 输出口连接到 Or 模块上,Color Fill 图层的 Interaction 模块也一样连接到 Or 模块。

You should see now that when we tap on Cancel or anywhere in the Color Fill the output of Or will trigger.

现在应该能看到,当我们点击 Cancel 或 Color Fill 中的任意一个时,Or 的输出将被触发。

Again, keep an eye on the inputs and outputs of these patches whilst tapping within the Viewer. 点击时盯着看模块的输出输入。

Replacing with Or 替换和或

We currently have only the Cancel Interaction Tap output connected to Turn Off the Switch. Replace that connection by connecting the output of Or to the Turn Off input of Switch.

我们目前只有 Cancel 图层的 Interaction 模块 Tap 输出口连接到Turn Off - Switch。
将 Or 模块的输出连接到 Switch 的 Turn Off 输入来替换该连接。

Now when we Tap on Color Fill or Cancel, the Turn Off of Switch is triggered.

现在当我们点击Color Fill Cancel 时,关闭开关。

Preparing for more logic 准备更多逻辑

A Color Fill layer takes up the full height and width of the Viewer by default. That means tapping anywhere on Send To (not just Cancel) triggers Switch to Turn Off and therefore Modal to close.

默认情况下,Color Fill 层的尺寸继承查看器的完整高度和宽度。
这意味着点击 Sent To 上的 任意位置(不只是Cancel)都能触发 Switch 模块关闭 Modal 图层。

To prevent this, we need to first know when Send To is being tapped. Add an Interaction patch for the Send To layer by selecting the layer and clicking Tap from the the Touch menu.

为了避免这种情况,我们需要先知道 Sent to 迪点击的时间。选中 Sent To 图层,点击 Touch 菜单中的 Tap 给 Sent To 图层添加一个 Interaction。

The new Interaction patch on the Patch Editor will now detect any Tap on Send To.

模块编辑器上的新 Interaction 模块将会检测到在 Sent To 上的所有点击。

Not 非

We want our Switch to Turn Off if Color Fill or Cancel are tapped, but not when Send To is tapped. Origami has an appropriately named Not patch for this purpose. Double-click on the Patch Editor ⌘⏎ and add in a Not patch ⏎.

如果点按了 Color Fil Cancel ,希望 Switch 关闭,但是 Sent To 图层被点击时。

Connect the Tap output of our Send To Interaction patch to the input of our Not patch. Observe the Not patch as the Send To layer is tapped in the Viewer. Pulses will appear briefly on the Not patch, respective to when the layer is tapped and not tapped.

连接 Sent To 图层的 Interaction 模块 Tap 输出口到 Not 模块的输入口。在查看器中点击 Sent To 图层,注意观察 Not 模块。脉冲将短暂出现在 Not 模块上,分别是当图层被点击和 被点击时。

A Tap in Origami lasts for one frame, so try tapping a few times to see changes.

And 和

The Switch should Turn Off when Cancel is tapped or Color Fill is tapped, and not when Send To is tapped. Origami has an And patch for this purpose. Double-click on the Patch Editor ⌘⏎ and add an And patch ⏎.

当 Cancel Color Fill 被点击时,开关应该关闭, 当 Sent To 被点击时。Origami 有一个 And 模块用于种目的。
添加一个 And 模块 Shift A

Connect the output of the Or patch directly to an input of the And patch. Then connect the output of the And patch to the Turn Off input of the Switch patch.

将 Or 模块的输出口连接到 And 模块的输入口。然后将 And 模块的输出口连接到 Switch 模块的 Turn Off。

Making a new connection where one already exists, such as the And output to Switch Turn Off input here, will replace any existing connections. 建立一个已经存在的新连接将替换旧的连接。

These connections and orderings allow the following logic to be checked:
这些连接和排序允许检查以下流程逻辑:

  • Have the Cancel layer or Color Fill layer been tapped?
    Cancel 图层 Color Fill 是否被点击?

  • And has something else happened?
    有其他的事件发送么?

You can now connect the Not output to the second And input to finish the last piece of logic.

您现在可以将 Not 模块的输出口连接到 And 模块的第二个输入口,以完成最后一个逻辑。

The final state of our three logic patches. 三个逻辑补丁最后的状态。

Our final logic to be checked is now:
现在要检查的最后的逻辑是:

  • Have the Cancel layer or Color Fill layer been tapped?
    Cancel 图层 Color Fill 是否被点击?

  • And has there not been tapping on Send To?
    点击到 Sent To 图层?

When you Tap Color Fill and Send To, Modal will not close. If you Tap Cancel or Color Fill elsewhere however, Modal will close.

点击 Color Fill 上的 Send To 区域时,Modal 不会关闭。点击Cancel Color Fill 的其他区域时, Modal 会关闭。


相关教程

7. Screen Transitions 屏幕切换
Create screen flows.

8. Timed Animations 延时动画
Create time-based, automatic animations.


相关案例

5. Facebook New Stories
当新闻滚动一定距离时触发提示出现。

16. Fahrenheit to Celsius
通过温度转换了解 Origami 中的逻辑和模块。

19. Instagram Direct Messages
向朋友发送Instagram直接消息,一次又一次地。


相关模块

Pop Animation Switch Transition Interaction Or Not And


NEXT UP
5. Scrolling Views 滚动
Add horizontal scroll behavior to your designs.


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,458评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,454评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,171评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,062评论 0 207
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,440评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,661评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,906评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,609评论 0 200
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,379评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,600评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,085评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,409评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,072评论 3 237
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,088评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,860评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,704评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,608评论 2 270

推荐阅读更多精彩内容