旋转图像超过180度

时间:2016-04-20 10:30:54

标签: ios swift rotation uianimation

我使用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)
    })}

1 个答案:

答案 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")
}
相关问题