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閱讀 230,002評論 6 542
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,400評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
    開封第一講書人閱讀 178,136評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,714評論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,452評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,818評論 1 328
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,812評論 3 446
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,997評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,552評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,292評論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,510評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,035評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,721評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,121評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,429評論 1 294
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,235評論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,480評論 2 379

推薦閱讀更多精彩內容