Example code of iOS self driving drawing effect
- 2021-09-16 08:20:13
- OfStack
1. General animation:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2];
frame.origin.x += 150;
[img setFrame:frame];
[UIView commitAnimations];
2. Continuous animation (1 series of images):
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"myImage1.png"],
[UIImage imageNamed:@"myImage2.png"],
[UIImage imageNamed:@"myImage3.png"],
[UIImage imageNamed:@"myImage4.png"], nil];
UIImageView *myAnimatedView = [[UIImageView alloc] initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImage;
myAnimatedView.animationRepeatCount = 0;
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[my AnimatedView release];
3.CATransition Public API:
CATransition *animation = [CATransition animation];
animation.duration = 0.5f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = KCAFillModeForwards;
// Various animation effects
/*
KCATransitionFade;
KCATransitionMoveIn;
KCATransitionPush;
KCATransitionReveal;
*/
/*
KCATransitionFromeRight;
KCATransitionFromLeft;
KCATransitionFormTop;
kCATransitionFromButtons;
*/
// Various combinations
animation.type = KCATransitionPush;
animation.subtype = KCATransitionFromRight;
[self.view.layer addAnimation:animation forKey:@"animation"];
4. UIView Animations animation:
[UIView beginAnimations:@"animationID" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationRepeatAutoreverses:NO];
// The following 4 Seed effect
/*
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFormLeft forView:self.view cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFormRight forView:self.view cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
*/
5. Use nesting, first get 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];
}
];
}
];