iOS CATransition 动画的简单使用

下面是实现的代码

//选择动画

- (IBAction)selectAnimationTypeButton:(id)sender {

    UIButton *button = sender;

    animationType animationType = button.tag;

    NSString *subtypeString;

    switch (_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;

    }

    

    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 OgleFlip:

            [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 CurlDow:

            [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 = 1;

    if (i > 6) {

        i = 1;

    }

    [self addBackgroundImgWithName:[NSString stringWithFormat:@"0%d.jpg",i]];

    i += 1;

}

#pragma CATransition========动画实现=======

- (void)transitionWithType:(NSString*) type withSubtype:(NSString*)subType forView:(UIView*)view{

    //创建CATranstion对象

    CATransition *animation = [CATransition animation];

    //设置运动时间

    animation.duration = DURATION;

    //设置动画的类型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)transtion{

    [UIView animateWithDuration:DURATION animations:^{

        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

        [UIView setAnimationTransition:transtion forView:view cache:YES];

    }];

}

 

- (void)addBackgroundImgWithName:(NSString*)imgeName{

    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:imgeName]];

}

代码放到github上,喜欢就给个Star:https://github.com/JakeTorres/Jake-sHouse

转载于:https://www.cnblogs.com/Jake-Chen-World/p/6559537.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值