核心动画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
*/

 

posted on 2015-05-15 12:57  快乐加油站789  阅读(140)  评论(0编辑  收藏  举报

导航