常用动画

转自:http://blog.csdn.net/richard_rufeng/article/details/17500095


第一、实现左右移动

[objc]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;">    [UIView beginAnimations:@"testAnimation" context:@"test"];  
  2.     [UIView setAnimationDuration:0.5];  
  3.    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  4.     [UIView setAnimationDelegate:self];  
  5.     [UIView setAnimationDidStopSelector:@selector(animationStop)];  
  6.     CGRect frame=self.myView.frame;  
  7.     frame.origin.x=10;  
  8.     self.myView.frame=frame;  
  9.     [UIView commitAnimations];  
  10. </span>  
第二、利用block来实现动画,回调简单方便

[objc]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;">    [UIView animateWithDuration:0.5 animations:^{  
  2.         CGRect frame=self.myView.frame;  
  3.            frame.origin.y=300;  
  4.             self.myView.frame=frame;  
  5.         //self.myView.alpha=0.0;  
  6.   
  7.     } completion:^(BOOL finished)  
  8.      {  
  9.          [UIView animateWithDuration:0.5 animations:^{  
  10.              //self.myView.alpha=1.0;  
  11.              CGRect frame=self.myView.frame;  
  12.              frame.origin.y=10;  
  13.              self.myView.frame=frame;  
  14.          }];  
  15.   
  16.      }];  
  17. </span>  
在completion后面的实现前面动画结束后的调用的方法

第三、实现渐入渐出得效果

[objc]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;">    [UIView animateWithDuration:0.5 animations:^{  
  2.   
  3.         self.myView.alpha = 0;  
  4.   
  5.     } completion:^(BOOL finished)  
  6.      {  
  7.          self.myView.alpha = 1;  
  8.      }];  
  9. </span>  

第四、实现放大缩小

[objc]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;">    self.myView.transform=CGAffineTransformScale(self.myView.transform11);  
  2.     [UIView animateWithDuration:0.5 animations:^{  
  3.   
  4.         self.myView.transform=CGAffineTransformScale(self.myView.transform0.10.1);  
  5.     } completion:^(BOOL finished)  
  6.      {  
  7.          [UIView animateWithDuration:0.5 animations:^{  
  8.              self.myView.transform=CGAffineTransformIdentity;  
  9.          }];  
  10.   
  11.      }];  
  12. </span>  

第五、两个动画间的过渡动画

上面讲的动画是针对一个动画的旋转、平移、放大缩小,我们分析两个动画在切换时的动画效果

[objc]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;">    [UIView beginAnimations:nil context:nil];  
  2.     [UIView setAnimationDuration:0.5];  
  3.     [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.parentView cache:YES];  
  4.     [UIView commitAnimations];  
  5.       
  6.     [self.parentView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];</span>  

Block方法的实现:

[objc]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;">    [UIView transitionWithView:self.parentView duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{  
  2.         [self.parentView exchangeSubviewAtIndex:1 withSubviewAtIndex:0];  
  3.     } completion:NULL];  
  4. </span>  


第六、修改pushviewcontroller切换动画效果

[objc]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;">    [UIView beginAnimations:nil context:nil];  
  2.     [UIView setAnimationDuration:0.5];  
  3.     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:YES];  
  4.     [UIView commitAnimations];  
  5.     UIViewController *viewContr = [[UIViewController alloc] init];  
  6.    [self.navigationController pushViewController:viewContr animated:NO];</span> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值