Swift:围绕中心点旋转图层
问题描述:
我有一个使用以(x,y)为中心的CAShape图层创建的图层。我想知道如何旋转它的中心。Swift:围绕中心点旋转图层
所以在上面的图片,我们如何旋转的指针? CGAffineTransform?或CABasicAnimation,必须使用什么以及如何使用(语法相同)。
答
设置您的UIElement图层“水平放置在容器中”&“垂直放置在容器中”首先在您的故事板中。然后,添加以下代码。
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(M_PI * 2.0)
rotateAnimation.duration = 1.0
rotateAnimation.repeatCount = Float.infinity
yourlayer.addAnimation(rotateAnimation, forKey: nil)