今回はAppleのプログラミングガイドを参考にキーフレームアニメーションを作成してみました。
Animation Types and Timing Programming Guide
作ったもの
コード
let animationView = UIView(frame: CGRect(x: view.frame.width / 2 - 150, y: view.frame.height / 2 - 100, width: 300, height: 200))
view.addSubview(animationView)
let images = [#imageLiteral(resourceName: "sample1.jpg"), #imageLiteral(resourceName: "sample2.jpg"), #imageLiteral(resourceName: "sample3.jpg")]
let cgImages = images.map { (image) -> CGImage in
let ciImage = CIImage(image: image)
return CIContext(options: nil).createCGImage(ciImage!, from: (ciImage?.extent)!)!
}
let animation = CAKeyframeAnimation(keyPath: "contents")
animation.repeatDuration = .infinity
animation.values = cgImages
animation.duration = 6.0
animationView.layer.add(animation, forKey: nil)
次に作るもの
[雑Memo]
- スワイプで回転する
- 上に近くにつれてだんだんと円が大きくなる