iOS动画汇总

iOS 简单动画主要分为三种(这是我的理解):

第一种:改变位置,大小等

[plain] view plain copy
  1. //开始动画   
  2. [UIView beginAnimations:nil context:nil];    
  3. //设定动画持续时间   
  4. [UIView setAnimationDuration:2];   
  5. //动画的内容   
  6. frame.origin.x += 150;   
  7. [img setFrame:frame];   
  8. //动画结束   
  9. [UIView commitAnimations];   


第二种:使用UIViewAnimationTransition


  1. [UIView beginAnimations:@"animation" context:nil];  
  2. [UIView setAnimationDuration:0.6f];  
  3. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  4. [UIView setAnimationDelegate:self];  
  5. [UIView setAnimationDidStopSelector:@selector(animationDidStop)];  
  6. [UIView setAnimationRepeatAutoreverses:NO];  
  7. [self.view addSubview:self.currentView];  
  8. [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:YES];  
  9. [UIView commitAnimations];  

UIViewAnimationTransition动画主要分为两种,
一种是掀开动画(就像翻日历),分别是 UIViewAnimationTransitionCurlUp , UIViewAnimationTransitionCurlDown .
另一种是翻转动画(一般地图和列表切换会使用这种),分别是UIViewAnimationTransitionCurlUp,    UIViewAnimationTransitionCurlDown .

就是上图的第一排4个按钮展现的动画

第三种:使用CATransition

[plain] view plain copy
  1. CATransition *transition = [CATransition animation];  
  2. transition.duration = 0.4;  
  3. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];  
  4. transition.type = kCATransitionPush;  
  5. transition.subtype = kCATransitionFromRight;  
  6. [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个方法:
[plain] view plain copy
  1. + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);  
  2.   
  3. + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0  
  4.   
  5. + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL  
  6.   
  7. + (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);  
  8.   
  9. + (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  

例如:改变大小位置
[plain] view plain copy
  1. [UIView animateWithDuration:0.6 animations:^{  
  2.         self.currentView.frame = CGRectMake(30, 30, 200, 300);  
  3.     }];  
或者翻转切换视图
[plain] view plain copy
  1. [UIView transitionFromView:self.mapviewContainer toView:self.listContainer duration:0.75 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished){  
  2.           
  3.     }];  

下面8个是私有api,如果应用要上appstore,请勿使用。
就是上图的下面8个按钮展现的动画



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值