代码改变世界

CABasicAnimation 3D旋转

2018-11-30 09:40  法子  阅读(448)  评论(0编辑  收藏  举报
        //动画为沿y轴旋转
        let animation = CABasicAnimation(keyPath: "transform.rotation.y")
        animation.fromValue = 0
        animation.toValue = Double.pi * 2
        animation.repeatCount = Float.infinity
        animation.duration = 2
        animatorView.layer.add(animation, forKey: "spin")
        
        //z轴td调大,防止旋转时被其他控件遮挡
        animatorView.layer.zPosition = 100
        
        //将view的tranform改为3d透视
        var transform = CATransform3DIdentity
        transform.m34 = 1.0 / 500.0//透视度
        animatorView.layer.transform = transform