感受一下,效果很酷炫
#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