I want to animate a UIView in a figure 8 motion. I am doing this in Swift using BezierPath but I want to add a delay to the animation.
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")
The figure 8 works just fine, but I have no idea how to add a delay. I have tried using methods like animateWithDuration(delay:options:animation:completion:) but that didn't help. If I am way off base and there is an easier way to animate a UIView in a 'Figure 8'/'Inifinity Loop' motion that would be fine. I just need the motion coupled with the delay.
Aucun commentaire:
Enregistrer un commentaire