先来介绍下苹果提供的API,如下:
/* Common transition types. */
CA_EXTERN NSString * const kCATransitionFade
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionMoveIn
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionPush
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionReveal
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
/* Common transition subtypes. */
CA_EXTERN NSString * const kCATransitionFromRight
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionFromLeft
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionFromTop
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionFromBottom
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CATransition *trAnimation = [CATransition animation];
trAnimation.duration = 1;
trAnimation.type = kCATransitionPush;
trAnimation.subtype = kCATransitionFromTop;
trAnimation.startProgress = 0.0;
trAnimation.endProgress = 1.0;
trAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.layer addAnimation:trAnimation forKey:@"transition"];
[self exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
trAnimation.type 苹果公开的类型仅仅有四种类型分别是:
淡化、推挤、揭开、覆盖
NSString * const kCATransitionFade;
NSString * const kCATransitionMoveIn;
NSString * const kCATransitionPush;
NSString * const kCATransitionReveal;
trAnimation.subtype 苹果提供的类型有如下四种:
从右侧、从左侧、从顶部、从底部
NSString * const kCATransitionFromRight;
NSString * const kCATransitionFromLeft;
NSString * const kCATransitionFromTop;
NSString * const kCATransitionFromBottom;
对于trAnimation.type类型苹果还提供了一定的私有API分别如下:
立方体、吸收、翻转、波纹、翻页、反翻页、镜头开、镜头关
animation.type = @"cube"
animation.type = @"suckEffect";
animation.type = @"oglFlip"; //不管subType is "fromLeft" or "fromRight",official只有一种效果
animation.type = @"rippleEffect";
animation.type = @"pageCurl";
animation.type = @"pageUnCurl"
animation.type = @"cameraIrisHollowOpen ";
animation.type = @"cameraIrisHollowClose ";
注意:使用trAnimation.type的私有API时有一定的局限性,我们都知道iOS APP如果上传到AppStroe是需要周左右的审核过程,如果你开发的APP是将要上传到AppStroe里面请一定不要使用这些私有API,因为苹果是禁止上传到AppStroe上的APP使用私有API。
CATransition的startProgress和endProgress属性介绍:
可以控制动画进行的过程,可以让动画停留在某个动画点上,值在0.0到1.0之间。endProgress要大于等于startProgress。比如上面的立方体转到,可以设置endProgress= 0.5,让动画停留在转动一般的位置。