翻页动画效果

可紊 提交于 2020-04-08 00:57:14
 1 typedef enum : NSUInteger {
 2     Fade = 1,                   //淡入淡出
 3     Push,                       //推挤
 4     Reveal,                     //揭开
 5     MoveIn,                     //覆盖
 6     Cube,                       //立方体
 7     SuckEffect,                 //吮吸
 8     OglFlip,                    //翻转
 9     RippleEffect,               //波纹
10     PageCurl,                   //翻页
11     PageUnCurl,                 //反翻页
12     CameraIrisHollowOpen,       //开镜头
13     CameraIrisHollowClose,      //关镜头
14     CurlDown,                   //下翻页
15     CurlUp,                     //上翻页
16     FlipFromLeft,               //左翻转
17     FlipFromRight,              //右翻转
18     
19 } AnimationType;
  1 - (IBAction)tapButton:(id)sender {
  2  
  3     UIButton * button = sender;
  4     AnimationType animationType = button.tag;
  5     
  6     NSString * subtypeString;
  7     
  8     switch (_subtype) {
  9         case 0:
 10             subtypeString = kCATransitionFromLeft;
 11             break;
 12         case 1:
 13             subtypeString = kCATransitionFromBottom;
 14             break;
 15         case 2:
 16             subtypeString = kCATransitionFromRight;
 17             break;
 18         case 3:
 19             subtypeString = kCATransitionFromTop;
 20             break;
 21         default:
 22             break;
 23     }
 24     
 25     _subtype += 1;
 26     if (_subtype > 3) {
 27         _subtype = 0;
 28     }
 29 
 30     
 31     switch (animationType) {
 32         case Fade:
 33             [self transitionWithType:kCATransitionFade WithSubtype:subtypeString ForView:self.view];
 34             break;
 35         
 36         case Push:
 37             [self transitionWithType:kCATransitionPush WithSubtype:subtypeString ForView:self.view];
 38             break;
 39             
 40         case Reveal:
 41             [self transitionWithType:kCATransitionReveal WithSubtype:subtypeString ForView:self.view];
 42             break;
 43             
 44         case MoveIn:
 45             [self transitionWithType:kCATransitionMoveIn WithSubtype:subtypeString ForView:self.view];
 46             break;
 47             
 48         case Cube:
 49             [self transitionWithType:@"cube" WithSubtype:subtypeString ForView:self.view];
 50             break;
 51         
 52         case SuckEffect:
 53             [self transitionWithType:@"suckEffect" WithSubtype:subtypeString ForView:self.view];
 54             break;
 55             
 56         case OglFlip:
 57             [self transitionWithType:@"oglFlip" WithSubtype:subtypeString ForView:self.view];
 58             break;
 59             
 60         case RippleEffect:
 61             [self transitionWithType:@"rippleEffect" WithSubtype:subtypeString ForView:self.view];
 62             break;
 63             
 64         case PageCurl:
 65             [self transitionWithType:@"pageCurl" WithSubtype:subtypeString ForView:self.view];
 66             break;
 67             
 68         case PageUnCurl:
 69             [self transitionWithType:@"pageUnCurl" WithSubtype:subtypeString ForView:self.view];
 70             break;
 71             
 72         case CameraIrisHollowOpen:
 73             [self transitionWithType:@"cameraIrisHollowOpen" WithSubtype:subtypeString ForView:self.view];
 74             break;
 75             
 76         case CameraIrisHollowClose:
 77             [self transitionWithType:@"cameraIrisHollowClose" WithSubtype:subtypeString ForView:self.view];
 78             break;
 79         
 80         case CurlDown:
 81             [self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlDown];
 82             break;
 83         
 84         case CurlUp:
 85             [self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlUp];
 86             break;
 87             
 88         case FlipFromLeft:
 89             [self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromLeft];
 90             break;
 91             
 92         case FlipFromRight:
 93             [self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromRight];
 94             break;
 95 
 96         default:
 97             break;
 98     }
 99     
100     static int i = 0;
101     if (i == 0) {
102         [self addBgImageWithImageName:IMAGE1];
103         i = 1;
104     }
105     else
106     {
107         [self addBgImageWithImageName:IMAGE2];
108         i = 0;
109     }
110     
111 }
 1 #pragma CATransition动画实现
 2 - (void) transitionWithType:(NSString *)type WithSubtype:(NSString *) subtype ForView : (UIView *) view
 3 {
 4     //创建CATransition对象
 5     CATransition * animation = [CATransition animation];
 6     
 7     //设置运动时间
 8     animation.duration = DURATION;
 9     
10     //设置运动type
11     animation.type = type;
12     if (subtype != nil) {
13         //设置子类
14         animation.subtype = subtype;
15     }
16     
17     //设置运动速度
18     animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
19     
20     [view.layer addAnimation:animation forKey:@"animation"];
21 }
22 
23 
24 
25 #pragma UIView实现动画
26 - (void) animationWithView:(UIView *)view WithAnimationTransition : (UIViewAnimationTransition) transition
27 {
28     [UIView animateWithDuration:DURATION animations:^{
29         [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
30         [UIView setAnimationTransition:transition forView:view cache:YES];
31     }];
32 }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!