아이폰 페이지 점프 애니메이션 패키지

3353 단어 iPhone
프로젝트에서 나는 페이지가 다른 애니메이션 효과를 가지기를 바란다. 나는 공용 코드를 제출하여 도구 종류로 쓰는 것을 좋아하는 사람이다. 이것도 놓치지 않을 것이다. 자, 코드를 보자.
글로벌 변수:
typedef enum{
    fade,
    moveIn,
    push,
    reveal,
    cube,
    suckEffect,
    oglFlip,
    rippleEffect,
    pageCurl,
    pageUnCurl,
    cameraIrisHollowOpen,
    cameraIrisHollowClose
}myAnimationType;

 
MyAnimationUtil.h
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
@interface MyAnimationUtil : NSObject
+(CATransition *)getAnimation:(myAnimationType)mytag;
@end

 
MyAnimationUtil.m
#import "MyAnimationUtil.h"

@implementation MyAnimationUtil


//    
+(CATransition *)getAnimation:(myAnimationType)mytag{
    
    CATransition *animation = [CATransition animation];
    animation.duration = 0.7;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    
    switch (mytag) {
        case fade:
            animation.type = kCATransitionFade;
            break;
        case push:
            animation.type = kCATransitionPush;
            break;
        case reveal:
            animation.type = kCATransitionReveal;
            break;
        case moveIn:
            animation.type = kCATransitionMoveIn;
            break;
        case cube:
            animation.type = @"cube";
            break;
        case suckEffect:
            animation.type = @"suckEffect";
            break;
        case oglFlip:
            animation.type = @"oglFlip";
            break;
        case rippleEffect:
            animation.type = @"rippleEffect";
            break;
        case pageCurl:
            animation.type = @"pageCurl";
            break;
        case pageUnCurl:
            animation.type = @"pageUnCurl";
            break;
        case cameraIrisHollowOpen:
            animation.type = @"cameraIrisHollowOpen";
            break;
        case cameraIrisHollowClose:
            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

 
호출된 코드:
CATransition* annim = [MyAnimationUtil getAnimation:cube];
    [[[UIApplication sharedApplication].delegate  window].layer addAnimation:annim forKey:nil];

좋은 웹페이지 즐겨찾기