###前提・実現したいこと
Swiftにてlayerをアニメーションさせる処理を書いています。
レイヤーポジションのアニメーションは問題なく機能しているのですが、やりたい事がもう1つ。
アニメーション中の特定のタイミングにてlayerのアニメーション画像を切り替えたいのです。
この条件のアニメーションを1つのCAAnimationで完結させたいと考えています。
###該当のソースコード
let animation = CAKeyframeAnimation(keyPath: "position")
animation.delegate = self
animation.duration = 4.5
animation.keyTimes = [0.0,0.44,0.66,0.78,1.0]
let path = UIBezierPath()
path.moveToPoint(view.layer.position)
path.addLineToPoint(firstPoint)
path.addQuadCurveToPoint(secondPoint, controlPoint: curvePoint)
path.addLineToPoint(secondPoint) // 今回アニメーション画像を切り替えたいタイミング
path.addLineToPoint(firstPoint)
animation.path = path.CGPath
animation.setValue(view.layer, forKey: "animation")
view.layer.addAnimation(animation, forKey: "animation")
view.layer.position = firstPoint
上記のコードですと
firstPoint → secondPoint → secondPoint(0.5秒ほどその場で待機) → firstPointに戻る
この様な流れになっているのですが、この0.5秒ほど待機している間だけlayerのアニメーション画像を切り替えたいと思っています。
###試したこと
let delay = 3.0 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue(), {
// layerのアニメーション画像を切り替える処理
})
この方法でも一応は実現できたのですが、今回は1つのCAAnimation内で完結させたいと考えています。
よろしくお願いします。
あなたの回答
tips
プレビュー