ios - UIImageView 旋转动画时的奇怪行为

标签 ios swift animation image-rotation

我正在尝试使用以下代码旋转 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/

相关文章:

ios - 在移动到下一个 View Controller 之前是否有必要关闭 View Controller

ios - 在 Swift 中准确测量时间以进行跨设备比较

html - 如何在 css3 中延迟每个循环动画?

android - 在 Ionic 框架中构建启动画面动画?

ios - 我可以使用 PNG 序列作为 SceneKit 对象上的动画 Material 吗?

ios - 在 ios 中的表格单元格中单击按钮更改图像

ios - #警告: C-style for statement is deprecated and will be removed in a future version of Swift

ios - 离开屏幕时,Tableview 部分标题无法正确转换

ios - Swift - 使用协议(protocol)和委托(delegate)将值传递回 ViewController

ios - Xcode Storyboard : Internal error. 请提交错误