iPhone页面跳转动画的封装

在项目中我希望页面跳转有不同的动画效果,我是一个喜欢将公用代码提交出来写成工具类的人,这个当然也不会放过,好了,看代码:

.h文件:

[cpp]  view plain copy
  1. #import <Foundation/Foundation.h>  
  2. #import <QuartzCore/QuartzCore.h>  
  3.   
  4. @interface MyAnimationUtil : NSObject {  
  5.       
  6. }  
  7.   
  8.   
  9. +(CATransition *)getAnimation:(NSInteger)mytag;  
  10.   
  11.   
  12. @end  

.m文件 

[cpp]  view plain copy
  1. #import "MyAnimationUtil.h"  
  2. #include<stdlib.h>  
  3.   
  4. @implementation MyAnimationUtil  
  5.   
  6.   
  7. //获得动画  
  8. +(CATransition *)getAnimation:(NSInteger)mytag{  
  9.       
  10.     CATransition *animation = [CATransition animation];  
  11.     animation.delegate = self;  
  12.     animation.duration = 0.7;  
  13.     animation.timingFunction = UIViewAnimationCurveEaseInOut;  
  14.       
  15.     switch (mytag) {  
  16.         case 1:  
  17.             animation.type = kCATransitionFade;  
  18.             break;  
  19.         case 2:  
  20.             animation.type = kCATransitionPush;  
  21.             break;  
  22.         case 3:  
  23.             animation.type = kCATransitionReveal;  
  24.             break;  
  25.         case 4:  
  26.             animation.type = kCATransitionMoveIn;  
  27.             break;  
  28.         case 5:  
  29.             animation.type = @"cube";  
  30.             break;  
  31.         case 6:  
  32.             animation.type = @"suckEffect";  
  33.             break;  
  34.         case 7:  
  35.             animation.type = @"oglFlip";  
  36.             break;  
  37.         case 8:  
  38.             animation.type = @"rippleEffect";  
  39.             break;  
  40.         case 9:  
  41.             animation.type = @"pageCurl";  
  42.             break;  
  43.         case 10:  
  44.             animation.type = @"pageUnCurl";  
  45.             break;  
  46.         case 11:  
  47.             animation.type = @"cameraIrisHollowOpen";  
  48.             break;  
  49.         case 12:  
  50.             animation.type = @"cameraIrisHollowClose";  
  51.             break;  
  52.         default:  
  53.             break;  
  54.     }  
  55.       
  56.      
  57.     int i = (int)rand()%4;  
  58.     switch (i) {  
  59.               
  60.         case 0:  
  61.             animation.subtype = kCATransitionFromLeft;  
  62.             break;  
  63.         case 1:  
  64.             animation.subtype = kCATransitionFromBottom;  
  65.             break;  
  66.         case 2:  
  67.             animation.subtype = kCATransitionFromRight;  
  68.             break;  
  69.         case 3:  
  70.             animation.subtype = kCATransitionFromTop;  
  71.             break;  
  72.         default:  
  73.             break;  
  74.     }  
  75.     return animation;  
  76. }  
  77.   
  78.   
  79. @end  

调用如下: 

[cpp]  view plain copy
  1. UserRegisterViewController *userregister = [[UserRegisterViewController alloc]initWithNibName:@"UserRegisterViewController" bundle:nil];  
  2. userregister.userregisterdelegate = self.rootdelegate;  
  3. [self.navigationController pushViewController:userregister animated:NO];  
  4. CATransition * animation =  [MyAnimationUtil getAnimation:6];  
  5. [self.navigationController.view.layer addAnimation:animation forKey:nil];  
  6. [userregister release];  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值