iOS 简单动画主要分为三种(这是我的理解):
第一种:改变位置,大小等
- //开始动画
- [UIView beginAnimations:nil context:nil];
- //设定动画持续时间
- [UIView setAnimationDuration:2];
- //动画的内容
- frame.origin.x += 150;
- [img setFrame:frame];
- //动画结束
- [UIView commitAnimations];
- [UIView beginAnimations:@"animation" context:nil];
- [UIView setAnimationDuration:0.6f];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDelegate:self];
- [UIView setAnimationDidStopSelector:@selector(animationDidStop)];
- [UIView setAnimationRepeatAutoreverses:NO];
- [self.view addSubview:self.currentView];
- [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:YES];
- [UIView commitAnimations];
一种是掀开动画(就像翻日历),分别是 UIViewAnimationTransitionCurlUp , UIViewAnimationTransitionCurlDown .
另一种是翻转动画(一般地图和列表切换会使用这种),分别是UIViewAnimationTransitionCurlUp, UIViewAnimationTransitionCurlDown .
就是上图的第一排4个按钮展现的动画

- CATransition *transition = [CATransition animation];
- transition.duration = 0.4;
- transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- transition.type = kCATransitionPush;
- transition.subtype = kCATransitionFromRight;
- [fromView.layer addAnimation:transition forKey:nil];
CATransition动画分为4种,
1、kCATransitionFade;
2、kCATransitionPush;
3、kCATransitionReveal;
4、kCATransitionMoveIn;
后三种又可以选择4个方向,kCATransitionFromLeft 、kCATransitionFromBottom 、kCATransitionFromRight 、kCATransitionFromTop
就是上图的第2排4个按钮展现的动画


从iOS4.0以后,apple又提供了5个方法:
- + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
- + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0
- + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL
- + (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
- + (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // toView added to fromView.superview, fromView removed from its superview
- [UIView animateWithDuration:0.6 animations:^{
- self.currentView.frame = CGRectMake(30, 30, 200, 300);
- }];
- [UIView transitionFromView:self.mapviewContainer toView:self.listContainer duration:0.75 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished){
- }];
下面8个是私有api,如果应用要上appstore,请勿使用。
就是上图的下面8个按钮展现的动画
就是上图的下面8个按钮展现的动画

