首页 > 解决方案 > 旋转动画发生时,UIImageView 未保留其中心

问题描述

我有一个 UIImageView,我从带有自动布局约束的 nib 加载。我试图将它旋转 180 度,但是当它旋转时,它没有保持自己的中心位置,因此形成了一个奇怪的旋转路径。我正在通过此代码旋转图像

//let center = self.viewAnimate.center
UIView.animate(withDuration: 1.3, delay: 0.0, options: [.repeat,.curveEaseInOut], animations: {
                    //self.viewAnimate.center = center
                    self.viewAnimate.transform = self.viewAnimate.transform.rotated(by: CGFloat(Double.pi))
}, completion: nil)

当我认为我可以强制它保持动画开始之前的中心位置时,注释部分就完成了。我该如何解决这个问题?

标签: iosswiftuiimageview

解决方案


推荐阅读