gpt4 book ai didi

ios - 为什么 UIImageView 只旋转一次?

转载 作者:搜寻专家 更新时间:2023-11-01 06:39:13 24 4
gpt4 key购买 nike

单击按钮时,我使用此代码行来旋转我的 UIImageView。但它只工作一次。如何在每次单击按钮时使其无限次?

self.imageView.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))

最佳答案

您必须使用 CGAffineTransformRotate 而不是 CGAffineTransformMakeRotation:

func rotateImageView() {   
UIView.animateWithDuration(1, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, CGFloat(M_PI_2))
}) { (finished) -> Void in
if finished {
self.rotateImageView()
}
}
}

如果你想停止它,你可以调用:

self.imageView.layer.removeAllAnimations()

关于ios - 为什么 UIImageView 只旋转一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37659125/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com