為以后總結ios開發工具類的備份,首先要在framework中引入QuatrtzCore.framework,在頭文件中需要
#import <QuartzCore/QuartzCore.h>
//.h 文件
-(void)createAnimation:(double) duration fillMode:(NSString *)model Type:(NSString *)type
subType:(NSString *)subtype removedOnCompletion:(BOOL)completion animationView:(id)view forkey:(NSString *)key;
//.m文件
-(void)createAnimation:(double)duration fillMode:(NSString *)model Type:(NSString *)type subType:(NSString *)subtype removedOnCompletion:(BOOL)completion animationView:(id)view forkey:(NSString *)key{
CATransition *animation =[CATransitionanimation ];
//是否代理
//animation.delegate = self;
//動畫時間 double類型
[animation setDuration:duration];
//動畫結束方式
[animation setFillMode:model];
/*動畫類型
kCATransitionFade;
kCATransitionMoveIn;
kCATransitionPush;
kCATransitionReveal;
*/
[animation setType:type];
/*動畫進入方式
kCATransitionFromRight;
kCATransitionFromLeft;
kCATransitionFromTop;
kCATransitionFromBottom;
*/
[animation setSubtype:subtype];
/*動畫時間控制
UIViewAnimationCurveEaseInOut, // slow at beginning and end
UIViewAnimationCurveEaseIn, // slow at beginning
UIViewAnimationCurveEaseOut, // slow at end
UIViewAnimationCurveLinear
animation.timingFunction = UIViewAnimationCurveEaseInOut;
*/
//是否在當前層完成動畫
[animation setRemovedOnCompletion:completion];
//動畫事件
[view addAnimation:animation forKey:key];
//釋放內存
animation =nil;
//return animation;
}
其中
animationView:(id)view 是根據傳入的對應的屬性去創建動畫如:
[self.window.layer addAnimation:animation forKey:key];