简体   繁体   English

swift 围绕中心旋转 animation

[英]swift rotate animation around center

I have imageView like vinyl record.我有像黑胶唱片一样的imageView And I want to create rotate animation.我想创建旋转 animation。 But if I use this code my vinyl record not exactly rotate around center.但是,如果我使用此代码,我的黑胶唱片不会完全围绕中心旋转。 In this animation my image a little bit shifts up and down.在这个 animation 中,我的图像有点上下移动。 How to fix it?如何解决?

func startRotateView(targetView: UIView, duration: Double = 3.0) {
        UIView.animate(withDuration: duration, delay: 0.0, options: .curveLinear, animations: {
            targetView.transform = targetView.transform.rotated(by: CGFloat(Double.pi))
        }) { finished in
            self.startRotateView(targetView: targetView, duration: duration)
        }
    }

Use CGAffineTransform instead of rotated使用CGAffineTransform而不是旋转

targetView.transform = CGAffineTransform(rotationAngle: .pi)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM