Iphone页面跳转动画的封装
程序员文章站
2022-05-24 13:21:37
...
在项目中我希望页面跳转有不同的动画效果,我是一个喜欢将公用代码提交出来写成工具类的人,这个当然也不会放过,好了,看代码:
全局变量:
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];
下一篇: Android 颜色使用总结
推荐阅读