我使用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)
})}
答案 0 :(得分:1)
您可以使用CABasicAnimation
旋转视图Clock-Wise
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")
}