美文网首页
iOS动画学习之旋转图形

iOS动画学习之旋转图形

作者: UniThan | 来源:发表于2016-06-28 22:18 被阅读647次

iOS动画旋转是对View的操作,而不是对layer的操作,关键点是需要设置锚点(anchorPoint),旋转轴和旋转度数

func spinAndTransform() { 
    // 1 
    layer.anchorPoint = CGPointMake(0.5, 0.6)  
    // 2 
    var rotationAnimation: CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation.z") 
    rotationAnimation.toValue = CGFloat(M_PI * 2.0) 
    rotationAnimation.duration = 0.45 
    rotationAnimation.removedOnCompletion = true 
    layer.addAnimation(rotationAnimation, forKey: nil)  
}

注意这里的anchorPoint取值是相对于旋转的view而言,取值0-1,也就是说锚点位于左上角,取值为(0,0),锚点位于右下角,取值为(1,1),其他点则介于这0-1之间,然后是设置旋转轴,这里是围绕z轴旋转,也就是和屏幕垂直的轴,设置旋转角度为360度,也就是2*PI。

相关文章

网友评论

      本文标题:iOS动画学习之旋转图形

      本文链接:https://www.haomeiwen.com/subject/iywtjttx.html