CABasicAnimation 3D旋轉
阿新 • • 發佈:2018-11-30
//動畫為沿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