Mimic UIAlertView Bounce?

前端 未结 4 1873
面向向阳花
面向向阳花 2020-12-23 02:15

Whats the best way to mimic the bouncing animation from the UIAlertView on the iPhone? Is there some built-in mechanism for this? The UIAlertView itself won\'t work for my n

4条回答
  •  一个人的身影
    2020-12-23 02:56

    UIAlertView uses a more sophisticated animation:

    • scale to larger than 100%
    • scale to smaller than 100%
    • scale to 100%

    Here's an implementation using a CAKeyFrameAnimation:

    view.alpha = 0;
    [UIView animateWithDuration:0.1 animations:^{view.alpha = 1.0;}];
    
    CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
    bounceAnimation.values = @[@0.01f, @1.1f, @0.8f, @1.0f];
    bounceAnimation.keyTimes = @[@0.0f, @0.5f, @0.75f, @1.0f];
    bounceAnimation.duration = 0.4;
    [view.layer addAnimation:bounceAnimation forKey:@"bounce"];
    

提交回复
热议问题