ios - 为什么我的 View 总是顺时针而不是逆时针旋转?

标签 ios swift

UIView.animateWithDuration(1.0, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
                var angle = degreesToRadians(180)
                self.imageView.transform = CGAffineTransformMakeRotation(-angle)
            }, completion: { (value: Bool) in })

为什么上述变换会顺时针而不是逆时针旋转我的 imageView?我怎样才能将此行为更改为后者?

编辑:

UIView.animateWithDuration(1.0, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
                    var angle = degreesToRadians(180)
                    self.imageView.transform = CGAffineTransformMakeRotation(angle)
                }, completion: { (value: Bool) in })

导致相同的行为发生。

最佳答案

动画试图以最小的旋转量旋转 View 。例如,给定所需的 90 度旋转,有多种方法可以通过旋转

的 View 来实现
90 + 360 * i

degrees, i 可以是任何整数,正数、负数或零。在这种情况下,动画会将 View 旋转 90 度,因为这是实现指定所需旋转的最小旋转量。另一个例子,即使你将所需的旋转设置为 450(90 + 360),动画仍然只会旋转 90 度。

在您的例子中,180 度实际上是旋转的反面。因此,180 和 -180 之间没有区别。如果您想强制 View 通过所需方向旋转,则必须将旋转分解为多个较小的旋转。在这种情况下,您可以将 View 旋转 90 度,然后再旋转 90 度,以确保 View 按照您想要的方向旋转。类似地,如果您希望它以相反的方向旋转,您可以依次旋转两次 -90 度。

关于ios - 为什么我的 View 总是顺时针而不是逆时针旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34596952/

相关文章:

ios - 如何为apple iap 服务器到服务器通知设置测试和生产环境

ios - 无法在装有 iOS 5.1.1 的设备上测试 App?

ios - WKWebView 正在尝试在后台运行,尽管它已关闭并且应该被处置

ios - Swift - 从 UIImagePickerController Camera 中选取时,UIImage 旋转了 90 度

ios - 从 AVAudioRecorder 获取分贝

ios - WatchKit 图像动画等待完成

ios - Sprite Kit 仅对屏幕左右边缘进行碰撞检测

android - Cordova 编译 android 不同于 ios

ios - 终止应用程序后从原来的位置播放视频

swift - 我们可以在 swift 中分别使用多个 UIViewController 中的 URLSessionDelegate 方法同时下载文件吗