How Do You CAKeyframeAnimation Scale?

后端 未结 4 1717
盖世英雄少女心
盖世英雄少女心 2020-12-28 10:02

I want to create an animation with several key frames. I want my Layer (a button in this case) to scale up to 1.5 then down to 0.5 then up to 1.2 then down to 0.8 then 1.0.<

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 10:06

    I don't know if you can use a CAKeyframeAnimation for animating the scale of a UIView, but you can do it with a CABasicAnimation and setting the fromValue and toValue properties, and using that to animate the transform property:

    - (CAAnimation*)monInAnimation 
    {
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
        animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)];
        animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(3.0, 3.0, 3.0)];
        [animation setDuration:1.5];
        [animation setAutoreverses:YES];
        return animation;
    }
    
    - (IBAction)monBtnIn 
    {
        [monButton.layer addAnimation:[self monInAnimation] forKey:@"transform"];
    }
    

提交回复
热议问题