iOS开发——动画编程Swift篇&(四)CABasicAnimation动画

时间:2022-06-11 19:38:23

CABasicAnimation动画

     //CABasicAnimation-不透明度
     @IBAction func cabOpacity()
     {
         let animation = CABasicAnimation(keyPath: "opacity")

         animation!.fromValue = 1.0
         animation!.toValue = 0.0
         animation.duration = 3.0
         self.testImageView.layer.addAnimation(animation, forKey: "Image-opacity")
         self.testImageView.alpha=0.0;
     }

     //开启 clip subview 属性
     @IBAction func cabExpend()
     {
         //从小到下(如果把Mode 属性改成 Center后,此效果为遮照)
         let animation = CABasicAnimation(keyPath: "bounds.size")
         animation!.fromValue = NSValue(CGSize: CGSizeMake(2.0, 2.0))
         animation!.toValue = NSValue(CGSize: self.testImageView.frame.size)
         animation.duration = 3.0
         self.testImageView.layer.addAnimation(animation, forKey: "Image-expen")
     }