在iOS中旋转对象

时间:2015-10-25 18:11:14

标签: ios swift ios9

如何使对象(例如图像)永远旋转?

UIView.animateWithDuration(2.0, animations: ({

    self.Cube.transform = CGAffineTransformMakeRotation(320)

}))

有没有人有解决方案,真的很感激一些帮助。

1 个答案:

答案 0 :(得分:0)

尝试此功能可永久旋转图层。

func rotateLayer(layer:CALayer,duration:CFTimeInterval){
    let animation = CABasicAnimation(keyPath: "transform.rotation");
    animation.fromValue = 0;
    animation.duration = duration;
    animation.toValue = CGFloat(M_PI*2);
    animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear);
    animation.repeatCount = Float.infinity;

    layer.addAnimation(animation, forKey: "rotation");
}

用法(持续时间是图层旋转360度所需的时间):

rotateLayer(subView.layer, duration: 2);