Iphone頁面跳轉動畫的封裝

來源:互聯網
上載者:User

在項目中我希望頁面跳轉有不同的動畫效果,我是一個喜歡將公用代碼提交出來寫成工具類的人,這個當然也不會放過,好了,看代碼:
.h檔案:
[cpp]
#import <Foundation/Foundation.h> 
#import <QuartzCore/QuartzCore.h> 
 
@interface MyAnimationUtil : NSObject { 
     

 
 
+(CATransition *)getAnimation:(NSInteger)mytag; 
 
 
@end 

.m檔案
[cpp]
#import "MyAnimationUtil.h" 
#include<stdlib.h> 
 
@implementation MyAnimationUtil 
 
 
//獲得動畫 
+(CATransition *)getAnimation:(NSInteger)mytag{ 
     
    CATransition *animation = [CATransition animation]; 
    animation.delegate = self; 
    animation.duration = 0.7; 
    animation.timingFunction = UIViewAnimationCurveEaseInOut; 
     
    switch (mytag) { 
        case 1: 
            animation.type = kCATransitionFade; 
            break; 
        case 2: 
            animation.type = kCATransitionPush; 
            break; 
        case 3: 
            animation.type = kCATransitionReveal; 
            break; 
        case 4: 
            animation.type = kCATransitionMoveIn; 
            break; 
        case 5: 
            animation.type = @"cube"; 
            break; 
        case 6: 
            animation.type = @"suckEffect"; 
            break; 
        case 7: 
            animation.type = @"oglFlip"; 
            break; 
        case 8: 
            animation.type = @"rippleEffect"; 
            break; 
        case 9: 
            animation.type = @"pageCurl"; 
            break; 
        case 10: 
            animation.type = @"pageUnCurl"; 
            break; 
        case 11: 
            animation.type = @"cameraIrisHollowOpen"; 
            break; 
        case 12: 
            animation.type = @"cameraIrisHollowClose"; 
            break; 
        default: 
            break; 
    } 
     
    
    int i = (int)rand()%4; 
    switch (i) { 
             
        case 0: 
            animation.subtype = kCATransitionFromLeft; 
            break; 
        case 1: 
            animation.subtype = kCATransitionFromBottom; 
            break; 
        case 2: 
            animation.subtype = kCATransitionFromRight; 
            break; 
        case 3: 
            animation.subtype = kCATransitionFromTop; 
            break; 
        default: 
            break; 
    } 
    return animation; 

 
 
 
@end 

調用如下:
[cpp]
UserRegisterViewController *userregister = [[UserRegisterViewController alloc]initWithNibName:@"UserRegisterViewController" bundle:nil]; 
   userregister.userregisterdelegate = self.rootdelegate; 
   [self.navigationController pushViewController:userregister animated:NO]; 
   CATransition * animation =  [MyAnimationUtil getAnimation:6]; 
   [self.navigationController.view.layer addAnimation:animation forKey:nil]; 
   [userregister release]; 


摘自 RiverAM的專欄

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.