核心动画 - CATransition

一、转场代码

缺点,现在只有三张图片。当i = 4的时候,就没有图片在出现了。

static int i = 1;

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSString *imageN = [NSString stringWithFormat:@"%d",i];
    
    _imageV.image = [UIImage imageNamed:imageN];
    
    i++;
}

 

二、修改动画

 // 转场代码
    if (i == 4) {
        i = 1;
    }
    // 加载图片名称
    NSString *imageN = [NSString stringWithFormat:@"%d",i];
    
    _imageView.image = [UIImage imageNamed:imageN];
    
    i++;

 

三、添加转场动画

转场动画只能和转场代码 写在一个方法中。不能分开到两个代码中。

static int i = 1;

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    if (i == 4) {
        i = 1;
    }
    
    NSString *imageN = [NSString stringWithFormat:@"%d",i];
    
    _imageV.image = [UIImage imageNamed:imageN];
    
    i++;
    
    // 转场动画
    CATransition *anim = [CATransition animation];
    anim.type = @"cube";
    [_imageV.layer addAnimation:anim forKey:nil];
}

 

四、有多少种动画

 anim.type = @"cube";

这行代码可以写成

posted on 2016-04-25 16:15  iOS学习-文  阅读(193)  评论(0)    收藏  举报

导航