令人敬畏的泰格伍兹 万维钢

Creating an intuitive animation is very simple and efficient in Apple’s brand new framework, SwiftUI. Before getting started, check out the video below to get to know what we are about to discuss.

在Apple的全新框架SwiftUI中 ,创建直观的动画非常简单且高效。 在开始之前,请查看下面的视频以了解我们将要讨论的内容。

In the above video, you saw five simple activity animations using different inbuilt solid shapes in SwiftUI.

在上面的视频中,您看到了五个简单的活动动画,它们在SwiftUI中使用了不同的内置实体形状 。

In SwiftUI, we can add animation to view animatable properties using .animation() modifier. There are the list of animatable properties in a view, like:

在SwiftUI中,我们可以使用.animation()修饰符添加动画以查看可设置动画的属性。 视图中有可设置动画的属性的列表,例如:

  1. Opacity不透明度
  2. Offset抵消
  3. Scale规模
  4. Frame帧
  5. etc…等等…

You should apply any one of the animatable properties to your view to get an animation effect using the .animation() modifier. A view with the .animation() modifier without any animatable property does nothing. Being this said, let’s get started.

您应该将任何可设置动画的属性应用于视图,以使用.animation()修饰符获得动画效果。 带有.animation()修饰符的视图没有任何可设置动画的属性,则不执行任何操作。 话虽如此,让我们开始吧。

Note: The animation GIFs are just for reference. Run the code in Xcode or check the above video to get actual animation smoothness.

注意:动画GIF仅作为参考。 运行Xcode中的代码或查看上面的视频以获取实际的动画平滑度。

3个滑动圈 (3 Sliding Circles)

3 Sliding Circles GIF
3滑圈GIF
  1. Create three circles using Circle shape in SwiftUI with 20x20 width and height.

    使用SwiftUI中的Circle形状(宽度和高度为20x20)创建三个圆形。

  2. Here, we are animating the offset of the circles, which makes circles move from left to right(➡️) and from right to left(⬅️).

    在这里,我们为圆​​的偏移设置了动画,使圆从左向右移动(➡️),从右向左移动(⬅️)。

  3. We have added a Timer which will trigger every 1.6 seconds to swap the offset value. Initially, offset will be at 100 (leftOffset), which makes circles move from left to right; after 1.6 seconds, leftOffset will be swapped as -100, which makes circles to move from right to left.

    我们添加了一个计时器 ,它将每1.6秒触发一次以交换偏移值。 最初,偏移将为100 (leftOffset),这将使圆从左移到右; 1.6秒后,leftOffset将交换为-100 ,这使圆从右向左移动。

  4. Why a 1.6-second timer? 1.6 seconds = 1 circle animation duration (1) + 2nd circle delay (0.2) + 3rd circle delay (0.4).

    为什么要使用1.6秒计时器? 1.6 秒= 1圈动画持续时间( 1 )+ 2圈延迟( 0.2 )+ 3圈延迟( 0.4 )。

  5. We have reduced the opacity of the circles to add a nice feel when moving from one side to another.从一侧移到另一侧时,我们降低了圆的不透明度,以增加良好的感觉。
  6. Did you notice a delay in the second and third circles? Yes, delay helps to start the animation after waiting for the mentioned delay. In our case, delay helps us to move circles one by one. If we didn’t mention delay, all circles would move at the same time.

    您是否注意到第二个和第三个圈子有所延迟 ? 是的,延迟有助于在等待上述延迟后启动动画。 就我们而言,延迟有助于我们一圈一圈地移动。 如果我们不提延误,那么所有圈子都会在同一时间移动。

  7. We have used default easeInOut animation with a one-second duration. There are plenty of animations available by default, like easeIn, easeOut, spring, etc… go ahead and play with it.

    我们使用了默认的easyInOut动画,持续时间为一秒 。 默认情况下,有很多动画可用,例如easyIn,easyOut,spring等,请继续播放。

水平滑杆 (Horizontal Sliding Bar)

Horizontal sliding bar GIF
水平滑杆GIF
  1. Create a RoundedRectangle shape with cornerRadius as 10 and frame of 80x20.

    创建一个RoundedRectangle形状,将cornerRadius设置为10并 80x20的帧。

  2. Here we are animating the offSet of the view. But this time, we have achieved the animation without the Timer. We have added shouldAnimate @State variable instead.

    在这里,我们为视图的偏移量设置了动画。 但是这次,我们实现了没有计时器的动画 我们添加了shouldAnimate @State变量。

  3. Whenever we change the shouldAnimate value, SwiftUI will re-render the view’s body property again. Initially, we have set it as false and .onAppear() we have set it as true, which triggers the animation.

    每当我们更改shouldAnimate值时,SwiftUI都会再次重新渲染视图的body属性。 最初,我们将其设置为false,并将.onAppear()设置为true,这将触发动画。

  4. How view comes back without swapping offset?

    令人敬畏的泰格伍兹 万维钢_使用SwiftUI创建令人敬畏的加载状态相关推荐

    1. 令人敬畏的泰格伍兹 万维钢_令人敬畏的桌面壁纸:Windows 7版

      令人敬畏的泰格伍兹 万维钢 Today we've got some awesome, high-quality, and just generally amazing desktop wallpap ...

    2. 令人敬畏的泰格伍兹 万维钢_5个令人敬畏的全新高级jQuery插件,2013年10月

      令人敬畏的泰格伍兹 万维钢 在这篇文章中,我们将分享2013年10月的5个Awesomely Premium jQuery插件 ,这些插件因其出色的功能而在"高级" Web开发人员 ...

    3. 万维钢_《高手——精英的见识和我们的时代》读书笔记_1

      李世政的读书笔记 书名 <高手--精英的见识和我们的时代> 作者 万维钢 出版社 中信出版社 阅读日期 20190516 书籍提纲 <序:精英的见识和我们的时代> 阅读前问题 ...

    4. 令人细思极恐的小故事_“&”号的令人惊讶的故事

      令人细思极恐的小故事 An ampersand is an invitation to imagine what will come next. It is a continuation of a c ...

    5. 豆瓣最高评分8.1!万维钢:读懂这本书,你会比身边人更深的理解这个时代

      ▲ 数据汪特别推荐 点击上图进入玩酷屋 小木用真金白银来给大家送礼物啦,特别感谢这些年一直以来大家对我们的支持,才让我们越做越好.(点我参与送礼活动) 这几年全球各大科技巨头纷纷进入人工智能领域,催生 ...

    6. 会讲故事的前物理学家万维钢解读、推荐过的书24本,好书一半

      图片来源:百度百科 最近几年看过的万维钢解读推荐过的书,前20本是得到APP上总结出来的,估计有遗漏,估计仅仅是得到有电子书的部分.后4本是在卖书网站上搜万维钢,结果中标明万维钢推荐的. 按4星.5星 ...

    7. 万维钢新书《你有你的计划,世界另有计划》_《丑小鸭定理》读书笔记

      <丑小鸭定理>的读后感想 首先抛出一个问题:到底是丑小鸭白天鹅之间的区别大,还是两只天鹅之间的差别大? 顺着这个问题,万维钢先指出一个俗见,就是大家的常见的认知:直观上当然是丑小鸭和天鹅之 ...

    8. 读书笔记之智识分子(万维钢)

      智识分子 --做一个复杂的现代人.[万维钢] 1."智识"--智慧和见识. 2.三个趋势(世界越来越复杂:人工智能正在慢慢取代人的工作:尽管所有人的物质生活都在改善,整个社会阶级分 ...

    9. 你有你的计划,世界另有计划这本书 万维钢

      你有你的计划而世界另有计划 首先推荐万维钢著作,免费领取:<<高手>万维钢 电子书>. 今天有个好消息,我的新书<你有你的计划,世界另有计划>马上就要开始独家首发了 ...

    最新文章

    1. 我又发现了7个让人心动的宝藏软件,很少有人知道
    2. Java报告比较日期_Java程序如果一个日期在另一个日期之后比较日期
    3. Android Training - 使用IntentService运行任务(Lesson 2 - 发送任务给IntentService)
    4. Gerrit代码审核服务器搭建全过程
    5. oracle 代码 字段映射,将ORACLE TIMESTAMP(9)字段映射到java.util.Date
    6. 多个project[项目]共享session
    7. python 将数组转化8位整数_int对象,永不溢出的整数
    8. win10 dns异常上不了网如何解决
    9. Java多线程学习二十八:原子类和 volatile 有什么异同?
    10. python中random is not defined_Python random库使用方法及异常处理方案
    11. 白话空间统计之:空间自相关
    12. 微信小程序input使用
    13. 五款优秀重复文件查找工具
    14. 冒险教主-超详细绘制教程
    15. Tablayout初始全部不选中,初始默认选中一个,初始全部选中的设置
    16. 手机电脑都能用,将照片转成PDF的免费方法
    17. 360email讲堂:中秋佳节邮件营销大放光彩
    18. 获取Word2vec训练得到的所有词与词向量
    19. 桌面的文件突然不见了怎么恢复
    20. Python对象赋值和拷贝

    热门文章

    1. 在UE5中创建一个受战锤启发的角色
    2. 2019年的咖啡大战,从杭州开打?
    3. Django+itchat+apscheduler实现向指定微信群和微信好友定时发送信息和文件
    4. iOS 17 开放侧载,微信双开要来了?
    5. 常用电路标记表示什么意思
    6. 软件测试实战(微软技术专家经验总结)--第九、十章(团队工作、个人管理)读书笔记
    7. 在html5中,用于获得用户当前位置的方法
    8. 2021.3.14学习随笔
    9. PADS VX2.8 基本规则的设置方法
    10. Java异常之 Error 和 Exception