ios - CGAffineTransform Rotate - 动画前跳转

标签 ios swift animation cgaffinetransform

我试图在按钮中创建动画旋转图像,但图像在动画之前跳跃,即旋转 180 度并开始动画

我的代码:

@IBAction func switchListButtonClick(sender: UIButton) {
    UIView.animateWithDuration(1) {
        self.switchListButton.imageView?.transform = CGAffineTransformRotate((self.switchListButton.imageView?.transform)!, CGFloat(-M_PI_2))
    }
}

我真的不明白为什么会发生这种情况?

请帮助我。

最佳答案

这对我有用

self.switchListButton.imageView!.clipsToBounds = false;
self.switchListButton.imageView!.contentMode = .Center;

UIView.animateWithDuration(1) {

    self.switchListButton.imageView?.transform = CGAffineTransformRotate((self.switchListButton.imageView?.transform)!, CGFloat(-M_PI_2))
}

虽然不完全确定,但我想下图可以说明上面的代码为何有效。您可以看到,当您旋转 UIView 时, View 的边界可能会改变并超出其父 View (下图中红线上方),因此如果您将 clipToBounds 设置为 true,则转换可能会失败.

enter image description here

关于ios - CGAffineTransform Rotate - 动画前跳转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37681920/

相关文章:

javascript动画因上面的元素而减慢

ios - 等待 Testflight 上的 Beta App Review

ios - 测试 iPhone 应用程序

swift - Ho 在段索引 chnage 上隐藏 ButtonBarPagerTabStripViewController 的 Childe View Controller

ios - 创建圆角时如何添加边框 UITextField Swift

css - 如何将 transform-origin 与 SVG 结合使用?

python - Spyder Python 动画不工作

ios - 计算今天和 future 日期之间的天数和小时数

ios - VS-MDA : Custom iOS-Framework in Plugin

cocoa - Swift 中没有外部名称的方法?