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。