#import "ViewAnimation.h"
#import <QuartzCore/QuartzCore.h>
#define kDuration 0.4 // 动画效果持续时间(秒)
@implementation
ViewAnimation
// 页面切换的方法
+( void )TransView1:(UIView*)v1 View2:(UIView*)v2 VC:(UIViewController *)vc;
{
CATransition *animation = [CATransition animation];
animation.delegate = self ;
animation.duration = kDuration;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
switch
(rand()%11) {
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
0:
animation.type = @ "cameraIrisHollowClose" ;
break ;
default :
animation.type = kCATransitionMoveIn;
break ;
}
switch
(rand()%3) {
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 :
animation.subtype = kCATransitionFromRight;
break ;
}
[vc.view addSubview:v2];
NSInteger
x1 = [[vc.view subviews]indexOfObject:v1];
NSInteger
x2 = [[vc.view subviews]indexOfObject:v2];
[vc.view exchangeSubviewAtIndex:x1 withSubviewAtIndex:x2];
[[vc.view layer]addAnimation:animation forKey:@ "animation" ];
}
@end
|