常用动画

来源:互联网 发布:词根背单词软件 编辑:程序博客网 时间:2024/04/29 12:41

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


第一、实现左右移动

[objc] view plaincopyprint?在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 plaincopyprint?在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 plaincopyprint?在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 plaincopyprint?在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 plaincopyprint?在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 plaincopyprint?在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 plaincopyprint?在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