0
使用此代码:连续旋转不集中
UIView.animate(withDuration: 0.5, delay: 0, options: [.repeat], animations: {
self.star.transform = self.star.transform.rotated(by: CGFloat(M_PI_2))
})
使用此代码:
extension UIView {
func rotate360Degrees(duration: CFTimeInterval = 3) {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(M_PI * 2)
rotateAnimation.isRemovedOnCompletion = false
rotateAnimation.duration = duration
rotateAnimation.repeatCount=Float.infinity
self.layer.add(rotateAnimation, forKey: nil)
}
}
Wel我都没有做我想做的事。正在旋转的视图是具有要填充的比例的UIImageView。我希望图像保持在中间。我怎么能做到这一点?这些函数在viewDidAppear中执行。最后的GIF看起来更好,但注意到这颗星并不是完美的中心... This is the image。