SoFunction
Updated on 2025-04-13

Example code with iOS's own animation effect

1. Ordinary animation:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2];
 += 150;
[img setFrame:frame];
[UIView commitAnimations];

2. Continuous animation (a series of images):

NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@""],
[UIImage imageNamed:@""],
[UIImage imageNamed:@""],
[UIImage imageNamed:@""], nil];
UIImageView *myAnimatedView = [[UIImageView alloc] initWithFrame:[self bounds]];
 = myImage;
 = 0;
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[my AnimatedView release];

Public API:

CATransition *animation = [CATransition animation];
 = 0.5f;
 = UIViewAnimationCurveEaseInOut;
 = KCAFillModeForwards;
//A variety of animation effects/*
KCATransitionFade;
KCATransitionMoveIn;
KCATransitionPush;
KCATransitionReveal;
*/
/*
KCATransitionFromeRight;
KCATransitionFromLeft;
KCATransitionFormTop;
kCATransitionFromButtons;
*/
//A variety of combinations = KCATransitionPush;
 = KCATransitionFromRight;
[ addAnimation:animation forKey:@"animation"];

Animations:

[UIView beginAnimations:@"animationID" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationRepeatAutoreverses:NO];
//The following four effects/*
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFormLeft forView: cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFormRight forView: cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView: cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView: cache:YES];
*/

5. Nested, grow bigger and then disappear

[UIView animateWithDuration:1.25 aniamtions:^{
    CGAffineTransform newTRansform = CGAffineTransformMakeScale(1.2, 1.2);
    [firstImageView setTransform:newTransform];
    [secondImageView setTransform:newTransform];
    completion:^(BOOL finished){
        [UIView animateWithDuration:1.2 animations:^{
            [firstImageView setAlpha:0];
            [secondImageView setAlpha:0];
        }
        completion:^(BOOL finished){
            [firstImageView removeFromSuperview];
            [secondImageView removeFromSuperview];
        }
        ];
    }
];

The above is the example code of iOS's own animation effects introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!