QuartzCore框架 CATransition动画

原创 2016年05月30日 16:32:23


#define kBackgroundColor1 [UIColor redColor]
#define kBackgroundColor2 [UIColor yellowColor]
#define kDurationTime 0.7f

@interface ViewController ()

@property (nonatomic,assign) int subType;

@end

typedef enum : NSUInteger{
    Fade = 1,               //淡入淡出
    Push,                   //推挤
    Reveal,                 //揭开
    MoveIn,                 //覆盖
    Cube,                   //立方体
    SuckEffect,             //吸附
    OglFlip,                //翻转
    RippleEffect,           //波纹
    PageCurl,               //翻页
    PageUnCurl,             //反翻页
    CameraIrisHollowOpen,   //开镜头
    CameraIrisHollowClose,  //关镜头
    CurlDown,               //下翻转
    CurlUp,                 //上翻转
    FlipFromLeft,           //左翻转
    FlipFromRight,          //右翻转
    
}AnimationType;


@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.subType = 0;
    
    [self showViewBgWithName:kBackgroundColor2];
    
}

- (IBAction)tagButtonAction:(id)sender {
    
    UIButton *button = sender;
    AnimationType animationType = button.tag;
    
    NSString *subtypeString;
    
    // 设置方向
    switch (self.subType) {
        case 0:
            subtypeString = kCATransitionFromLeft;
            break;
        case 1:
            subtypeString = kCATransitionFromBottom;
            break;
        case 2:
            subtypeString = kCATransitionFromRight;
            break;
        case 3:
            subtypeString = kCATransitionFromTop;
            break;
        default:
            break;
    }
    
    _subType += 1;
    if (_subType > 3) {
        _subType = 0;
    }
    
    // QuartzCore 动画
    switch (animationType) {
        case Fade:
            [self transitionWithType:kCATransitionFade WithSubtype:subtypeString ForView:self.view];
            break;
            
        case Push:
            [self transitionWithType:kCATransitionPush WithSubtype:subtypeString ForView:self.view];
            break;
            
        case Reveal:
            [self transitionWithType:kCATransitionReveal WithSubtype:subtypeString ForView:self.view];
            break;
            
        case MoveIn:
            [self transitionWithType:kCATransitionMoveIn WithSubtype:subtypeString ForView:self.view];
            break;
            
        case Cube:
            [self transitionWithType:@"cube" WithSubtype:subtypeString ForView:self.view];
            break;
            
        case SuckEffect:
            [self transitionWithType:@"suckEffect" WithSubtype:subtypeString ForView:self.view];
            break;
            
        case OglFlip:
            [self transitionWithType:@"oglFlip" WithSubtype:subtypeString ForView:self.view];
            break;
            
        case RippleEffect:
            [self transitionWithType:@"rippleEffect" WithSubtype:subtypeString ForView:self.view];
            break;
            
        case PageCurl:
            [self transitionWithType:@"pageCurl" WithSubtype:subtypeString ForView:self.view];
            break;
            
        case PageUnCurl:
            [self transitionWithType:@"pageUnCurl" WithSubtype:subtypeString ForView:self.view];
            break;
            
        case CameraIrisHollowOpen:
            [self transitionWithType:@"cameraIrisHollowOpen" WithSubtype:subtypeString ForView:self.view];
            break;
            
        case CameraIrisHollowClose:
            [self transitionWithType:@"cameraIrisHollowClose" WithSubtype:subtypeString ForView:self.view];
            break;
            
            
            
            
        case CurlDown:
            [self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlDown];
            break;
            
        case CurlUp:
            [self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlUp];
            break;
            
        case FlipFromLeft:
            [self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromLeft];
            break;
            
        case FlipFromRight:
            [self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromRight];
            break;
            
        default:
            break;
    }
    
    static int i = 0;
    if (i == 0) {
        [self showViewBgWithName:kBackgroundColor1];
        i = 1;
    }else{
        [self showViewBgWithName:kBackgroundColor2];
        i = 0;
    }
}

- (void)showViewBgWithName:(UIColor *)color{
    self.view.backgroundColor = color;
}


#pragma mark CATransition 动画实现
- (void)transitionWithType:(NSString *)type WithSubtype:(NSString *)subType ForView:(UIView *)View{
    
    //创建Catransition对象
    CATransition *animation = [CATransition animation];
    
    //设置运动时间
    animation.duration = kDurationTime;
    
    //设置运动type
    animation.type = type;
    
    if (subType != nil) {
        // 设置子类
        animation.subtype = subType;
    }
    
    // 设置运动速度
    animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
    
    [View.layer addAnimation:animation forKey:@"animation"];
    
}


#pragma mark UIView 实现动画
- (void)animationWithView:(UIView *)view WithAnimationTransition:(UIViewAnimationTransition)transition{
    
    [UIView animateWithDuration:kDurationTime animations:^{
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationTransition:transition forView:view cache:YES];
    }];
}


@end


相关文章推荐

iOS 动画初探序一:QuartzCore框架与CoreAnimation的前世今生

前言:首先我们来看QuartzCore框架:框架中我们可以看到有如下头文件: CoreAnimation.h是做APP动画、特效绝对的主角。头文件包含了以下内容:有如下头文件: 在来看QuartzCo...
  • Xoxo_x
  • Xoxo_x
  • 2017年05月09日 00:11
  • 294

QuartzCore 之 CAAnimation 动画详解

介绍: 核心动画, 提供丰富易用的API, 可以写出复杂交互性强的动画, 应用于Mac OS 和 iOS平台, 动画执行过程是在后台操作的, 不会影响主线程. 今天就来介绍一些API的示例使用. 下面...

CATransition动画

  • 2015年06月03日 15:02
  • 71KB
  • 下载

iOS开发之 转场动画CATransition

转场动画CATransition入门须知: 1、 CATransition 转场动画 可以切换视图 视图控制器  2、CATransition 的两个重要属性 ...

动画浅析-CAAnimation和CATransition

现在明白了,要做动画。需要用到CATransition类! 那就学习一下吧! 先贴一个入门代码! [_imgPic setImage:image];// 设置新的图片...

CATransition的动画效果类型及实现方法

实现iphone漂亮的动画效果主要有两种方法,一种是UIView层面的,一种是使用CATransition进行更低层次的控制, 第一种是UIView,UIView方式可能在低层也是使用CATrans...
  • a287971
  • a287971
  • 2012年05月31日 11:20
  • 514

CATransition—转场动画

转载自:http://www.jianshu.com/p/267ba592254c 一、简介 CATransition是CAAnimation的子类,用于做转场动画能够为图层提...

CATransition 动画的参考解析

CATransition *animation = [CATransition animation];     animation.delegate = self;     animation.d...

ios 动画效果CATransition笔记

初学ios开发,很多概念还不清楚,所以只有边学边做例子。又怕学了后面忘了前面,因此用自己的博客来纪录自己的学习历程,也是对自己学习不要懈怠做个监督。     刚学ios做动画效果。因为ios封装得很好...

Swift学习笔记(1)过渡动画(CATransition和UIViewAnimation)的用法

Swift学习笔记(1)过渡动画(CATransition和UIViewAnimation)的用法CATransition和UIViewAnimation是场景切换时常用的两种过渡动画目录Swift学...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:QuartzCore框架 CATransition动画
举报原因:
原因补充:

(最多只允许输入30个字)