swift学习iOS之Swift绘图动画程序员

iOS动画(一):时钟动画(Swift)

2017-09-05  本文已影响242人  Andy_Ron

参考:

一、直接做动画

现在就完成了文章开头的效果。

二、代码说明

  1. 关于anchorPoint(锚点)
    如果注释掉分针和时针视图,并且关掉动画效果和锚点设置:
//        secondHandView.layer.anchorPoint = CGPoint(x: 0.5, y: 1)
//        minuteHandView.center = view.center
//        self.view.addSubview(minuteHandView)
//        hourHandView.center = view.center
//        self.view.addSubview(hourHandView)
        
        // 创建CADisplayLink,并将其添加到主线程中
//        let link = CADisplayLink(target: self, selector: #selector(ViewController.clockRunning))
//        link.add(to: RunLoop.main, forMode: .defaultRunLoopMode)

加上secondHandView.layer.anchorPoint = CGPoint(x: 0.5, y: 1)后:

anchorPoint的官方描述:

Defines the anchor point of the layer's bounds rectangle. Animatable.
You specify the value for this property using the unit coordinate space. The default value of this property is (0.5, 0.5), which represents the center of the layer’s bounds rectangle.

All geometric manipulations to the view occur about the specified point.

For example, applying a rotation transform to a layer with the default anchor point causes the layer to rotate around its center. Changing the anchor point to a different location would cause the layer to rotate around that new point.

anchorPoint的值在 (0,0)(1,1)之间。默认是 (0.5, 0.5),代表锚点在中心位置。 (0,0)(1,1)分别代表左上角和右上角。

  1. 关于CALayer的属性positionanchorPoint
  1. CADisplayLink 与 NSTimer

代码和图片位置: 89-Animation/clock

欢迎您访问我的的微信公众号:欣欣向戎(微信号: andy_ron1587 )!
上一篇 下一篇

猜你喜欢

热点阅读