简体   繁体   English

旋转图像超过180度

[英]Rotate image more than 180 degrees

I'm using CGAffineTransformMakeRotation to transform and rotate an arrow in a meter. 我正在使用CGAffineTransformMakeRotation来转换和旋转仪表中的箭头。

Picture of arrow that animates inside gage 在测量仪内部动画的箭头的图片

The problem I am facing is that when I rotate more then 180 degrees the arrow rotates counter clockwise. 我面临的问题是,当我旋转超过180度时,箭头逆时针旋转。

My goal is to rotate the arrow clockwise in the range of 1 to 280 degrees. 我的目标是顺时针旋转1到280度的箭头。

Example of the function that rotates the arrow: 旋转箭头的函数示例:

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)
    })}

You can use CABasicAnimation to rotate the view Clock-Wise 您可以使用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")
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM