Ios 将视图无限旋转360度
我正在使用此代码无限旋转视图360度。但我的观点并非如此:Ios 将视图无限旋转360度,ios,swift,Ios,Swift,我正在使用此代码无限旋转视图360度。但我的观点并非如此: func rotateImageView() { UIView.animate(withDuration: 3.0, delay: 0, options: [.repeat, .curveLinear], animations: { self.vinylView.transform = CGAffineTransform(rotationAngle: .pi * 2) })
func rotateImageView() {
UIView.animate(withDuration: 3.0, delay: 0, options: [.repeat, .curveLinear], animations: {
self.vinylView.transform = CGAffineTransform(rotationAngle: .pi * 2)
})
}
如何修复它?用/替换pi*,删除重复,添加完成并调用如下函数:
private func rotateImageView() {
UIView.animate(withDuration: 3, delay: 0, options: .curveLinear, animations: {
self.vinylView.transform = self.vinylView.transform.rotated(by: .pi / 2)
}) { (finished) in
if finished {
self.rotateImageView()
}
}
}
使用Cabasicanization的解决方案
//旋转视图
乙烯基视图.layer.add(cabasicaniation.rotation,forKey:nil)
扩展卡巴斯基化{
静态let旋转:卡巴斯基化={
让动画=CABASICANIATION(关键路径:“transform.rotation.z”)
animation.repeatCount=.infinity//将视图无限旋转360度
animation.fromValue=0
animation.toValue=CGFloat.pi*2
animation.duration=3.0
返回动画
}()
}
这是否回答了您的问题?UIView.animate将“查看”图像/视图的最终形式,以确定如何对其设置动画,因此当您通过.pi*2变换图像时,UIView.animate没有发现任何不同,因此似乎什么也不做。您可以尝试将动画分成几个部分,然后逐个调用它们。