欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

点击的动画效果

程序员文章站 2022-05-02 20:06:34
...
func scaleAnimation() {
        let scaleAnim1 = CABasicAnimation(keyPath: "transform")
        scaleAnim1.fromValue = NSValue(CATransform3D: CATransform3DIdentity)
        scaleAnim1.toValue = NSValue(CATransform3D: CATransform3DMakeScale(0.97, 0.97, 1.0))
        scaleAnim1.fillMode = kCAFillModeForwards
        scaleAnim1.duration = 0.2
        scaleAnim1.beginTime = 0
        scaleAnim1.removedOnCompletion = true
        
        let scaleAnim2 = CABasicAnimation(keyPath: "transform")
        scaleAnim2.toValue = NSValue(CATransform3D: CATransform3DIdentity)
        scaleAnim2.fillMode = kCAFillModeForwards
        scaleAnim2.duration = 0.1
        scaleAnim2.beginTime = 0.2
        scaleAnim2.removedOnCompletion = true
        
        let animGroup = CAAnimationGroup()
        animGroup.animations = [scaleAnim1,scaleAnim2]
        animGroup.duration = 0.3
        animGroup.removedOnCompletion = true
        animGroup.delegate = self
        self.layer.addAnimation(animGroup, forKey: "scaleAnimation")
    }