将图像旋转超过 180 度
Rotate image more than 180 degrees
我正在使用 CGAffineTransformMakeRotation 来变换和旋转米中的箭头。
Picture of arrow that animates inside gage
我面临的问题是,当我旋转超过 180 度时,箭头会逆时针旋转。
我的目标是在1到280度的范围内顺时针旋转箭头。
旋转箭头的函数示例:
func rotateNeedel(value: Int){
var value = 220 //for testing purpose
let degrees:CGFloat = CGFloat(value)
UIView.animateWithDuration(2.0, animations: {
self.ImgMaalerArrow.transform = CGAffineTransformMakeRotation((degrees * CGFloat(M_PI)) / 180.0)
})}
您可以使用CABasicAnimation
顺时针旋转视图
func rotateNeedel(value: Double, duration: Double){
let fullRotation = CABasicAnimation(keyPath: "transform.rotation")
fullRotation.fromValue = Double(0)
fullRotation.toValue = Double((value * M_PI)/180)
fullRotation.fillMode = kCAFillModeForwards
fullRotation.duration = duration
fullRotation.removedOnCompletion = false
// add animation to your view
self.ImgMaalerArrow.layer.addAnimation(fullRotation, forKey: "rotateViewAnimation")
}
我正在使用 CGAffineTransformMakeRotation 来变换和旋转米中的箭头。
Picture of arrow that animates inside gage
我面临的问题是,当我旋转超过 180 度时,箭头会逆时针旋转。
我的目标是在1到280度的范围内顺时针旋转箭头。
旋转箭头的函数示例:
func rotateNeedel(value: Int){
var value = 220 //for testing purpose
let degrees:CGFloat = CGFloat(value)
UIView.animateWithDuration(2.0, animations: {
self.ImgMaalerArrow.transform = CGAffineTransformMakeRotation((degrees * CGFloat(M_PI)) / 180.0)
})}
您可以使用CABasicAnimation
顺时针旋转视图
func rotateNeedel(value: Double, duration: Double){
let fullRotation = CABasicAnimation(keyPath: "transform.rotation")
fullRotation.fromValue = Double(0)
fullRotation.toValue = Double((value * M_PI)/180)
fullRotation.fillMode = kCAFillModeForwards
fullRotation.duration = duration
fullRotation.removedOnCompletion = false
// add animation to your view
self.ImgMaalerArrow.layer.addAnimation(fullRotation, forKey: "rotateViewAnimation")
}