1 //设置旋转 2 let rotationAnimation:CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation.z") 3 //rotationAnimation.toValue = CGFloat(M_PI_2) * rotateCount 4 rotationAnimation.fromValue = CGFloat(M_PI_2) * rotateCount 5 rotationAnimation.toValue = CGFloat(M_PI_2) * (++rotateCount) 6 rotationAnimation.removedOnCompletion = false 7 rotationAnimation.fillMode = kCAFillModeForwards 8 //设置缩放 9 let scaleAnimation:CABasicAnimation = CABasicAnimation(keyPath: "transform.scale") 10 if self.rotateCount % 2 == 1 { 11 scaleAnimation.fromValue = 1.0 12 scaleAnimation.toValue = 0.75 13 scaleAnimation.duration = 1.0;
14 scaleAnimation.removedOnCompletion = false 15 scaleAnimation.fillMode = kCAFillModeForwards
//设置 动画不回到起始位置,这两个要一起设置。
16 } 17 //设置动画组 18 let animationGroup:CAAnimationGroup = CAAnimationGroup() 19 animationGroup.duration = 1.0 20 animationGroup.repeatCount = 0 21 animationGroup.animations = [rotationAnimation,scaleAnimation] 22 animationGroup.removedOnCompletion = false 23 animationGroup.fillMode = kCAFillModeForwards 24 //组编动画 25 self.VIDEO.playerLayer.addAnimation(animationGroup, forKey: "animationGroup")
设置视频player显示的比例按照视频本身比例显示
1 func rotateAction(){ 2 let rotationAnimation:CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation.z") 3 rotationAnimation.fromValue = CGFloat(M_PI_2) * rotateCount 4 rotationAnimation.toValue = CGFloat(M_PI_2) * (++rotateCount) 5 let scaleAnimation:CABasicAnimation = CABasicAnimation(keyPath: "transform.scale") 6 if self.rotateCount % 2 == 1 { 7 scaleAnimation.fromValue = 1.0 8 let boolCompare = (self.cast.video_height / self.cast.video_width) >= 1 ? true : false 9 if self.isLive() { 10 if boolCompare { 11 scaleAnimation.toValue = (self.VIDEO.width) / (self.VIDEO.height) 12 } else { 13 scaleAnimation.toValue = (self.VIDEO.height) / (self.VIDEO.width) 14 } 15 } else if !self.isIpadCompact(){ 16 if boolCompare { 17 scaleAnimation.toValue = (self.VIDEO.width) / (self.VIDEO.height) 18 } else { 19 scaleAnimation.toValue = (self.VIDEO.height) / (self.VIDEO.width) 20 } 21 } else { 22 var ratio = (self.VIDEO.height) / (self.VIDEO.width) 23 if ratio > 2 { 24 ratio = 1.8 25 } else if ratio > 1 { 26 ratio = 1.65 27 } 28 scaleAnimation.toValue = ratio 29 } 30 scaleAnimation.duration = 0.2; 31 } 32 let animationGroup:CAAnimationGroup = CAAnimationGroup() 33 animationGroup.duration = 0.2 34 animationGroup.repeatCount = 0 35 animationGroup.animations = [rotationAnimation,scaleAnimation] 36 animationGroup.removedOnCompletion = false 37 animationGroup.fillMode = kCAFillModeForwards 38 self.VIDEO.playerLayer.addAnimation(animationGroup, forKey: "animationGroup") 39 }