我想以数字 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/