简体   繁体   中英

swift rotate animation around center

I have imageView like vinyl record. And I want to create rotate 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. 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

targetView.transform = CGAffineTransform(rotationAngle: .pi)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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