我正在尝试使用以下代码旋转 UIImageView:
var x = -((self.needleImage.frame.size.width/2) - 15) //x for rotation point
UIView.animateWithDuration(5.0, delay: 10.0, options: nil, animations: {
var transform = CGAffineTransformMakeTranslation(x, 0)
transform = CGAffineTransformRotate(transform, CGFloat(-M_PI_2))
transform = CGAffineTransformTranslate(transform, -x, 0)
self.needleImage.transform = transformm
结束位置是正确的,但在动画/旋转期间,图像在稳定在正确位置之前稍微向左移动。
我尝试使用来自 this 的 UIView 执行相同的代码但它并没有这样做。
然后我尝试将 Imageview 包装在 View 中并旋转它,但这也没有帮助。
我在旋转点上画了一个圆柱来检查它是否在正确的位置,但看起来还不错。
最佳答案
我过去曾使用此代码片段永久旋转 View ,但通过删除最后一个闭包,它应该可以将图像旋转 360 度。这当然是可以调整的。现在它设置为 2PI。您必须将旋转角度转换为弧度。
func animateRotator() {
UIView.animateWithDuration(0.5, delay: 0, options: .CurveLinear, animations: { () -> Void in
self.rotator.transform = CGAffineTransformRotate(self.rotator.transform, CGFloat(M_PI_2))
}) { (finished) -> Void in
self.animateRotator()
}
}
关于ios - UIImageView 旋转动画时的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32050354/