IOS CATransition 立体动画效果

 

 

感受一下,效果很酷炫

 

 

#import "ViewController.h"

 

@interface ViewController (){

    NSArray *array; //图片数组

    NSInteger _index; //数组下标

}

 

@property (nonatomic,strong)UIImageView *image;

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    _index = 0;

    self.view.backgroundColor = [UIColor whiteColor];

    for (int i = 0; i < 2; i ++) {

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

        button.frame = CGRectMake(50 + i * 160, 400, 60, 40);

        button.tag = 300 + i;

        button.backgroundColor = [UIColor orangeColor];

        [button addTarget:self action:@selector(action_button:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:button];

    }

    

    array = @[@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg"];

    

    _image = [[UIImageView alloc]initWithFrame:CGRectMake(10, 120, 375 - 20, 200)];

    _image.image = [UIImage imageNamed:array[0]];

    [self.view addSubview:_image];

 

}

 

- (void)action_button:(UIButton *)sender{

    switch (sender.tag) {

        case 300:{

            /*

             TYPE 的类型

             pageCurl            向上翻一页

             pageUnCurl          向下翻一页

             rippleEffect        滴水效果

             suckEffect          收缩效果,如一块布被抽走

             cube                立方体效果

             oglFlip             上下翻转效果

             */

            

            if (_index > 0) {

                _index --;

            }else{

                _index = array.count - 1;

            }

            _image.image = [UIImage imageNamed:array[_index]];

            CATransition *animation = [CATransition animation];

            animation.type = @"oglFlip";

            animation.subtype = kCATransitionFromLeft;

            animation.duration = 1.0f;

            [_image.layer addAnimation:animation forKey:@""];

            

        }break;

        case 301:{

            if (_index < array.count - 1) {

                _index ++;

            }else{

                _index = 0;

            }

            _image.image = [UIImage imageNamed:array[_index]];

            CATransition *animation = [CATransition animation];

            animation.type = @"cube";

            animation.subtype = kCATransitionFromRight;

            animation.duration = 1.0f;

            [_image.layer addAnimation:animation forKey:@""];

        }break;

        default:

            break;

    }

}

 

 

@end

若有任何问题,请联系673636634@qq.com

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值