IOS CATransition 立体动画效果

来源:互联网 发布:网络投放 编辑:程序博客网 时间:2024/05/17 18:46



感受一下,效果很酷炫


#import "ViewController.h"


@interface ViewController (){

    NSArray *array;//图片数组

    NSInteger _index;//数组下标

}


@property (nonatomic,strong)UIImageView *image;


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    _index =0;

    self.view.backgroundColor = [UIColorwhiteColor];

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

        UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];

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

        button.tag =300 + i;

        button.backgroundColor = [UIColororangeColor];

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

        [self.viewaddSubview:button];

    }

    

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

    

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

    _image.image = [UIImageimageNamed:array[0]];

    [self.viewaddSubview:_image];


}


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

    switch (sender.tag) {

        case300:{

            /*

             TYPE 的类型

             pageCurl            向上翻一页

             pageUnCurl          向下翻一页

             rippleEffect        滴水效果

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

             cube                立方体效果

             oglFlip             上下翻转效果

             */

            

            if (_index >0) {

                _index --;

            }else{

                _index =array.count -1;

            }

            _image.image = [UIImageimageNamed:array[_index]];

            CATransition *animation = [CATransitionanimation];

            animation.type =@"oglFlip";

            animation.subtype =kCATransitionFromLeft;

            animation.duration =1.0f;

            [_image.layeraddAnimation:animation forKey:@""];

            

        }break;

        case301:{

            if (_index <array.count -1) {

                _index ++;

            }else{

                _index =0;

            }

            _image.image = [UIImageimageNamed:array[_index]];

            CATransition *animation = [CATransitionanimation];

            animation.type =@"cube";

            animation.subtype =kCATransitionFromRight;

            animation.duration =1.0f;

            [_image.layeraddAnimation:animation forKey:@""];

        }break;

        default:

            break;

    }

}



@end


0 0
原创粉丝点击