转场动画

  1 /*
  2  CATransaction 转场动画 可以切换视图 视图控制器
  3  Type 转场动画 的动画效果
  4  subtype 转场动画效果方向
  5  
  6  
  7 */
  8 #import "ViewController.h"
  9 #import "NextViewController.h"
 10 
 11 typedef enum Direction{
 12     Right = 0,
 13     Left,
 14 } Direction;
 15 
 16 @interface ViewController ()
 17 {
 18     NSArray *imageList;
 19     UIImageView *showImage;
 20     int index;
 21 }
 22 @end
 23 
 24 @implementation ViewController
 25 
 26 - (void)viewDidLoad {
 27     [super viewDidLoad];
 28     self.view.backgroundColor = [UIColor redColor];
 29     
 30     imageList = @[@"1",@"8fac777" ];
 31     showImage = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
 32     showImage.image = [UIImage imageNamed:@"1"];
 33     [self.view addSubview:showImage];
 34     showImage.userInteractionEnabled = YES;
 35     UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(RightswipeAction)];
 36     swipe.direction = UISwipeGestureRecognizerDirectionRight;
 37     
 38     [self.view addGestureRecognizer:swipe];
 39     
 40     UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipeAction)];
 41     swipe.direction = UISwipeGestureRecognizerDirectionLeft;
 42     
 43     [self.view addGestureRecognizer:leftSwipe];
 44 
 45     UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
 46     [self.view addGestureRecognizer:longPress];
 47 }
 48 
 49 
 50 #pragma mark--------跳转到下一个页面-----
 51 - (void)longPressAction:(UILongPressGestureRecognizer *)sender{
 52     if (sender.state == UIGestureRecognizerStateBegan) {
 53         NextViewController *next = [[NextViewController alloc]init];
 54         CATransition *animation = [CATransition animation];
 55         animation.type = @"rippleEffect";
 56         animation.subtype = kCATransitionFromRight;
 57         animation.duration = 1;
 58         
 59         [self.navigationController pushViewController:next animated:NO];
 60     }
 61     
 62    
 63 }
 64 
 65 - (void)didCHangeImageWithDirection:(Duration)direction{
 66     
 67     index = direction == Right ? [self countRelease] : [self countAdd];
 68     
 69 
 70     CATransition *transition = [CATransition animation];
 71     transition.type = direction == Right ? @"cube" : @"rippleEffect";
 72     transition.subtype = direction == Right ? kCATransitionFromRight : kCATransitionFromLeft;
 73     transition.duration = 1;
 74     [showImage.layer addAnimation:transition forKey:nil];
 75     
 76     showImage.image = [UIImage imageNamed:imageList[index]];
 77 }
 78 
 79 #pragma mark---------向左滑动图片加---------
 80 //需要 通过方向 判断 是自加 还是自减 把计算号的值 赋给 全局变量
 81 - (int)countAdd{
 82     index ++;
 83     
 84 //    如果超出了 图片数组的元素 修复成0 没有超出 返回增加后的值
 85     return index = index >= imageList.count ? 0 : index;
 86 
 87 }
 88 #pragma mark---------向右滑动图片减---------
 89 - (int)countRelease{
 90     index --;
 91     return index<0 ? (int)imageList.count-1:index;
 92 }
 93 
 94 - (void)RightswipeAction{
 95     [self didCHangeImageWithDirection:Right];
 96 
 97 }
 98 
 99 - (void)leftSwipeAction{
100     [self didCHangeImageWithDirection:Left];
101     
102 }

 

转载于:https://www.cnblogs.com/liYongJun0526/p/4874144.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值