3.5. 滚动 Scrolling Views - Origami Studio教程


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

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


Add horizontal scroll behavior to your designs. 添加垂直滚动。

Scrolling views are easy to build in Origami and highly flexible too. We're going to learn how to use scroll by creating a basic Messenger prototype. Make sure you download the tutorial files to follow along.

滚动视图在 Origami 里超简单啊。怎么给消息列表添加一个基础的滚动呢?下载好教程文件,跟着一步一步来。

Setting up 配置

Once you have the tutorial files open, you might notice that we have a layer named List set up below the Navigation Bar and the Tab Bar in our Layers panel. Take note of how the List layer is anchored to the top, and positioned exactly below the Navigation Bar.

打开标记为(开始)的文件,图层窗口中 Navigation Bar 和 Tab Bar 下面由一个叫 List 的图层。注意 List 图层的锚点,图层被锚定到顶部,并且位于 Navigation Bar 下面一层被遮挡了一部分。

Adding scroll interaction 添加滚动交互

We can add Scroll to our layer just like any other type of interaction. Hover over the List layer, click the Touch button, and since we want vertical scrolling, select Scroll Y from the menu.

鼠标悬停到 List 图层上,点击 Touch 菜单里的 Scroll Y ,编辑器中添加了一个 Scroll 模块。

Our List layer is now scrollable with all the behaviors you would expect from something scrollable — things like velocity and rubber banding etc.

现在 List 图层可以滚动了。

Try scrolling the List layer within the Viewer. 试着在查看器中滚动 List 图层。

Containing a scroll 创建容器

You might have noticed that adding Scroll interaction to the layer reset its position to 0
, clipping the Navigation Bar from view. Hide the Navigation Bar layer to see the List layer is now positioned at the top of the screen, rather than below the Navigation Bar as intended.

你肯能注意到了 List 图层被 Navigation Bar 遮盖了一步分,不是按照预期位从 Navigation Bar 下面开始滚动。

Another issue is at the very bottom of the scroll. The prototype is not taking into account that our Tab Bar is in the way.This Scroll should be contained above the Tab Bar.

还有一个问题就是结束滚动后,List 图层没有在 Tab Bar 上面,底部被 Tab Bar 挡住了。

We need to contain our List view Scroll to the space between the Navigation Bar and the above the Tab Bar. We can do this with a Group layer.

解决这俩问题需要把 List 的滚动范围限制在 Navigation Bar 和 Tab Bar 之间。可以用组 Group 图层解决。

Add a Group by clicking on the New Layer button Shift Cmd N, and selecting Group. Make sure the Group is placed below the Navigation Bar and Tab Bar layers.

新建一个 Group ,按 Shift Cmd N 打开新图层下拉框,选择 Group。把 Group 放在 Navigation Bar 和 Tab Bar 下面。

Visual alignment 对齐

It can be useful to temporarily add a Color Fill to a new Group layer, just to see how much space it is occupying. Add in a Color Fill layer by clicking on the New Layer button Shift Cmd N, and adding in a Color Fill. Move your Color Fill layer into Group.

在 Group 内添加一个 Color Fill 图层,用来检查 Group 的大小。按 Shift Cmd N 打开新图层下拉框,选择 Color Fill,把 Color Fill 拖到 Group 内。

板栗:这步和上一步觉得可以调一下,先添加 Color Fill,选中 Color Fill 按 Cmd G 给 Color Fill 添加一个父级 Group。

Groups have no visible state (only their content), hence why Color Fill is going to sit in Group temporarily. 因为 Group 是没有颜色的,只有在里面放一个填充颜色才能看到这个 Group 的尺寸和位置。

Re-enable the Navigation Bar for the remaining steps.

Adjusting our container 调整容器尺寸

The layer size of Group is the same size as the device screen by default. The screen width is fine in the case, as our List content fits within it. Our height however needs some tweaking.

默认情况下 Group 图层的尺寸和屏幕的尺寸一样。List 的宽度和屏幕宽度一样,所以宽度保持不变,只需要调整高度就行了。

The height we wish to achieve is equivalent to the device screen height minus the height of the Navigation Bar layer, 64.5, minus the height of the Tab Bar layer, 49.

高度等于屏幕高度减去 Navigation Bar 图层的高度64.5,减去Tab Bar 图层的高度 49

Select the Group layer. In the Size H property inside the Layers panel, enter 667-49-64.5 and hit Return.

选中 Group 图层,在属性 Size H 中输出 -64.5-49,按 Return 确定。

You should see a new Size H value of 553.5 appear. 可以看到计算出的新高度值。

Aligning our container 对齐容器位置

In in the Viewer you should see that the List (underneath our Color Fill) is not perfectly aligned with our new height values. This is because our Group is still anchored to the center of the screen.

在查看器中可以到看到计算后的新高度值也没有对齐 List 图层(Color Fill 下方)。这是因为 Group 图层对齐屏幕的中心。

Change the Anchor of our Group to the top of the screen. Then change the Group Y position to the height of the Navigation Bar, which was 64.5. You should then see that our Group (and Color Fill) are now perfectly aligned in our prototype.

将 Group 的锚点改为上中点,Y 轴位置输入和 Navigation Bar 一样的64.5。现在 Group 的位置和原型一致了。

The Y position is measured from the top of the screen, since that is how we positioned our Anchor. Y 轴位置从屏幕顶部测量是由锚点决定的。

Ordering the container

Now that the Group is correctly placed, we can delete our temporary Color Fill, and drag our layer List inside the Group.

现在 Group 在正确的位置上,可以临时图层 Color Fill 了,并将 List 拖动到 Group 内。

You can now give the prototype a spin in the Viewer. Notice how List is now neatly constrained between the top Navigation Bar and the bottom Tab Bar.

完成。


相关教程

6. Horizontal Scrolling 水平滚动
创建水平分页滚动。

7. Screen Transitions 屏幕切换
创建页面流程


案例

11. Messenger Home
滚动对话列表。
▲ 教程文件里的

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

6. Facebook Popular Events
创建一个简单的水平滚动。


相关模块

Scroll Scroll Settings


相关图层

Group Color Fill


NEXT UP
6. Horizontal Scrolling 水平滚动
创建水平分页滚动。


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

推荐阅读更多精彩内容