LoginSignup
0
0

More than 5 years have passed since last update.

Swiftでキーフレームアニメーションを作ってみた

Last updated at Posted at 2018-04-04

今回はAppleのプログラミングガイドを参考にキーフレームアニメーションを作成してみました。
Animation Types and Timing Programming Guide

作ったもの

anime.gif

コード

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]

  • スワイプで回転する
  • 上に近くにつれてだんだんと円が大きくなる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0