【问题标题】:Rotate image more than 180 degrees将图像旋转 180 度以上
【发布时间】:2016-04-20 10:30:53
【问题描述】:

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

【问题讨论】:

标签: ios swift rotation uianimation


【解决方案1】:

您可以使用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")
}

【讨论】:

  • 太棒了! :D 非常感谢
猜你喜欢
  • 2013-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-20
  • 2017-05-07
  • 1970-01-01
  • 2011-11-19
  • 2011-10-12
相关资源
最近更新 更多