yipingios

核心动画04-CATransition转场动画

Transition:过度,执行一些过度动画,比如两个界面切换的时候,push就是一种过度动画

模拟翻书效果:通过按钮模拟左右滑动,index标记当前的图片的下标名

#pragma make 上一张
- (IBAction)previous:(UIButton *)sender {
    
    self.index--;
    if (self.index == -1) {
        self.index = 8;
    }
    
    self.iconView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",self.index + 1]];
    
    //转场动画
    CATransition *anim = [CATransition animation];
//    anim.type = @"cube";  // 动画过渡类型
//    动画的方向,枚举类型,四种方向
//    anim.subtype = kCATransitionFromLeft;  // 动画过渡方向
    
    anim.type = @"pageUnCurl";
    anim.duration = 0.5;  // 动画持续1s
    
    //动画加到哪个layer上面
    [self.iconView.layer addAnimation:anim forKey:nil];
}

#pragma make 下一张
- (IBAction)next:(id)sender {
    
    self.index++;
    if (self.index == 9) {
        self.index = 0;
    }
    
    self.iconView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",self.index + 1]];
    
    //转场动画
    CATransition *anim = [CATransition animation];
    anim.type = @"pageCurl";
    anim.duration = 0.5;
    
    //从百分之多少开始动画
    anim.startProgress = 0.5;
    
    //从百分之多少结束动画
    anim.endProgress = 0.8;
    
    // 代理,动画执行完毕后会调用delegate的animationDidStop:finished:
//    anim.delegate = self;
    
    [self.iconView.layer addAnimation:anim forKey:nil];
}

过度效果和过度方向例举

/* 过渡效果 
fade     //交叉淡化过渡(不支持过渡方向) kCATransitionFade 
push     //新视图把旧视图推出去 kCATransitionPush  moveIn   //新视图移到旧视图上面 kCATransitionMoveIn 
reveal   //将旧视图移开,显示下面的新视图 kCATransitionReveal 
cube     //立方体翻滚效果 
oglFlip  //上下左右翻转效果 
suckEffect   //收缩效果,如一块布被抽走(不支持过渡方向) 
rippleEffect //滴水效果(不支持过渡方向) 
pageCurl     //向上翻页效果 
pageUnCurl   //向下翻页效果 
cameraIrisHollowOpen  //相机镜头打开效果(不支持过渡方向) 
cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)
*/   

/* 过渡方向
 kCATransitionFromRight 
kCATransitionFromLeft 
kCATransitionFromBottom 
kCATransitionFromTop
*/

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
  • 2022-02-14
  • 2021-08-09
  • 2022-12-23
  • 2021-12-27
猜你喜欢
  • 2021-07-03
  • 2022-12-23
  • 2021-12-05
  • 2021-10-01
  • 2021-07-02
  • 2021-10-20
相关资源
相似解决方案