iSO 简单的转场动画的实现

- (void)viewDidLoad {
    [super viewDidLoad];
    self.imageArr = @[@"timg.jpg", @"timg1.jpg", @"timg2.jpg", @"timg3.png"];
    _index = 0;
    // Do any additional setup after loading the view.
    UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(50, 100, self.view.frame.size.width - 100, 400)];
    image.backgroundColor = [UIColor redColor];
    image.image = [UIImage imageNamed:_imageArr[_index]];
    [self.view addSubview:image];
    _image = image;
    
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    _index++;
    if(_index > 3){
        _index = 0;
    }
    _image.image = [UIImage imageNamed:_imageArr[_index]];

//转场动画用CATransition 可以轻松的实现
    CATransition * anim = [CATransition animation];
//type 是战场动画的样式,苹果提供了不少样式, 可以根据自己的需求进行选择
    anim.type = @"suckEffect";
//转场时间
    anim.duration = 1.0f;
    [_image.layer addAnimation:anim forKey:nil];
}

你可能感兴趣的:(iSO 简单的转场动画的实现)