• CALayer CABasicAnimation 组动画的设置,设置动画不回到初始位置


     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     }
  • 相关阅读:
    BZOJ3672/UOJ7 [Noi2014]购票
    POJ3718 Facer's Chocolate Dream
    BZOJ1453:[WC]Dface双面棋盘
    BZOJ2957:楼房重建
    AtCoder Grand Contest 009 D:Uninity
    BZOJ2877:[NOI2012]魔幻棋盘
    BZOJ3065:带插入区间K小值
    BZOJ3489:A simple rmq problem
    浅谈主席树
    AtCoder Regular Contest 080 E:Young Maids
  • 原文地址:https://www.cnblogs.com/741162830qq/p/4935586.html
Copyright © 2020-2023  润新知