LoginSignup
5
5

More than 5 years have passed since last update.

読み込みに使えそうなアニメーション2 〜Windows10風〜

Last updated at Posted at 2016-11-10

開発環境

  • XCode8.1
  • Swift3

20161110.gif

Windows10のアップデート中のアニメーションを見てて、なんとなく作ってみた。

githubへのリンクは以下
LoadingAnimationSample

元にしたサンプルはクックパッドの開発ブログにあるやつ。
心地よいアニメーションを求めて
CAReplicatorLayerはここで初めて知った。

        // CAReplicatorLayerを生成、追加
        let replicatorLayer = CAReplicatorLayer()
        replicatorLayer.frame = view.bounds
        view.layer.addSublayer(replicatorLayer)

        let circle = Circlelayer()
        circle.frame = CGRect(x: self.view.frame.midX-40, y: self.view.frame.midY - 80, width: 80, height: 80)
        replicatorLayer.addSublayer(circle)
        circle.setNeedsDisplay()

        let animation = CAKeyframeAnimation(keyPath: "position")
        animation.fillMode = kCAFillModeForwards
        animation.isRemovedOnCompletion = false
        animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)

        let x : CGFloat = self.view.frame.size.width/2
        let y : CGFloat = self.view.frame.size.height/2
        let radius : CGFloat = 100.0

        let cyclePath : CGMutablePath = CGMutablePath()
        cyclePath.addArc(center: CGPoint(x:x, y:y), radius: radius, startAngle: CGFloat(M_PI*(3/2)), endAngle: CGFloat(-M_PI*(1/2)), clockwise: false)

        animation.path = cyclePath

        let blinkAnimation = CAKeyframeAnimation(keyPath: "opacity")
        blinkAnimation.fillMode = kCAFillModeForwards
        blinkAnimation.isRemovedOnCompletion = false
        blinkAnimation.values = [1, 0, 1, 1, 1]

        let group = CAAnimationGroup()
        group.animations = [animation, blinkAnimation]
        group.duration = 5
        group.repeatCount = .infinity

        circle.add(group, forKey: nil)

        replicatorLayer.instanceCount = 6
        replicatorLayer.instanceDelay = 0.1
        let angle = (2.0*M_PI)/30
        replicatorLayer.instanceTransform = CATransform3DMakeRotation(-CGFloat(angle), 0.0, 0.0, 1.0);

5
5
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
5
5