ios - 延迟沿着 BezierPath 动画 UIView

标签 ios swift animation uiview uibezierpath

我想以数字 8 的 Action 为 UIView 设置动画。我正在使用 BezierPath 在 Swift 中执行此操作,但我想为动画添加延迟。

let center: CGPoint = CGPoint(x: 60, y: 45)
let cent: CGPoint = CGPoint(x: 90, y: 45)
let radius: CGFloat = 15.0
let start: CGFloat = CGFloat(M_PI)
let end: CGFloat = 0.0
let path1: UIBezierPath = UIBezierPath(arcCenter: center, radius: radius, startAngle: start, endAngle: end, clockwise: true)
let path2: UIBezierPath = UIBezierPath(arcCenter: cent, radius: radius, startAngle: -start, endAngle: end, clockwise: false)
let path3: UIBezierPath = UIBezierPath(arcCenter: cent, radius: radius, startAngle: end, endAngle: -start, clockwise: false)
let path4: UIBezierPath = UIBezierPath(arcCenter: center, radius: radius, startAngle: end, endAngle: start, clockwise: true)
let paths: UIBezierPath = UIBezierPath()
paths.appendPath(path1)
paths.appendPath(path2)
paths.appendPath(path3)
paths.appendPath(path4)

let anim: CAKeyframeAnimation = CAKeyframeAnimation(keyPath: "position")
anim.path = paths.CGPath
anim.repeatCount = 2.0
anim.duration = 3.0

view.layer.addAnimation(anim, forKey: "animate position along path")

图 8 工作得很好,但我不知道如何添加延迟。我尝试过使用 animateWithDuration(delay:options:animation:completion:) 之类的方法,但这没有帮助。如果我离题太远,并且有一种更简单的方法可以在“图 8”/“无限循环”运动中为 UIView 设置动画,那会很好。我只需要 Action 加上延迟。

最佳答案

动画对象有开始时间。将其设置为您想要的任何数量的 future 。

anim.beginTime = CACurrentMediaTime() + 1.0

此示例将延迟 1 秒开始。

使用 dispatch_after block 启动整个动画方法可能会在短期内获得相同的结果,但可能会抑制调整或操作动画相对于开始时的其他计时功能的能力 future 的时间。调整动画本身的时间可以使动画对象的计时状态保持一致。

关于ios - 延迟沿着 BezierPath 动画 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38003614/

相关文章:

iPhone 应用程序 : how to get app icon from app id?

ios - SwiftUI:如何在物理配置的设备上预览 View ?

ios - Firebase 横幅广告未加载

objective-c - 添加到图层后水平翻转 CCSprite

ios - UILabel 帧大小动画不适用于 ios8

jquery老虎机效果,不使用gif文件做动画

ios - ALAMOFIRE 发布请求图像下载并在 Collection View 中绑定(bind)

ios - 如何在我从上一个屏幕选择的日期执行 +1 或 -1?

ios - 快速编辑 UITableView 行项目

ios - 从 Swift 数组中删除具有重复属性的对象