UIImageView 动画旋转时的时髦行为
Funky behavior when animating rotation of UIImageView
我正在尝试使用以下代码旋转 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
结束位置是正确的,但在animation/rotation期间,图像在稳定在正确位置之前稍微向左移动了一点。
我用 this 的 UIView 尝试了相同的代码,但它没有这样做。
然后我尝试将 Imageview 包裹在一个 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()
}
}
我正在尝试使用以下代码旋转 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
结束位置是正确的,但在animation/rotation期间,图像在稳定在正确位置之前稍微向左移动了一点。
我用 this 的 UIView 尝试了相同的代码,但它没有这样做。
然后我尝试将 Imageview 包裹在一个 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()
}
}