【发布时间】:2016-06-23 23:47:43
【问题描述】:
我想为UIView 制作 8 字形动作的动画。我正在使用 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 设置动画,那很好。我只需要动作加上延迟。
【问题讨论】:
-
你是如何开始围绕路径的视图动画的?
-
还是
addAnimation触发启动?我现在正在操场上做这个 -
addAnimation 启动它。
-
谢谢。我会在一个小项目中尝试一下
标签: ios swift animation uiview uibezierpath