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.012 scaleAnimation.toValue = 0.7513 scaleAnimation.duration = 1.0; 14 scaleAnimation.removedOnCompletion = false15 scaleAnimation.fillMode = kCAFillModeForwards //设置 动画不回到起始位置,这两个要一起设置。 16 }17 //设置动画组18 let animationGroup:CAAnimationGroup = CAAnimationGroup()19 animationGroup.duration = 1.020 animationGroup.repeatCount = 021 animationGroup.animations = [rotationAnimation,scaleAnimation]22 animationGroup.removedOnCompletion = false23 animationGroup.fillMode = kCAFillModeForwards24 //组编动画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.825 } else if ratio > 1 {26 ratio = 1.6527 }28 scaleAnimation.toValue = ratio29 }30 scaleAnimation.duration = 0.2;31 }32 let animationGroup:CAAnimationGroup = CAAnimationGroup()33 animationGroup.duration = 0.234 animationGroup.repeatCount = 035 animationGroup.animations = [rotationAnimation,scaleAnimation]36 animationGroup.removedOnCompletion = false37 animationGroup.fillMode = kCAFillModeForwards38 self.VIDEO.playerLayer.addAnimation(animationGroup, forKey: "animationGroup")39 }