iOS原生转场动画的调用与总结

2018-09-21  本文已影响74人  流年划过颜夕
typedef enum : NSUInteger {
Fade = 1,                   //淡入淡出
Push,                       //推挤
Reveal,                     //揭开
MoveIn,                     //覆盖
Cube,                       //立方体
SuckEffect,                 //吮吸
OglFlip,                    //翻转
RippleEffect,               //波纹
PageCurl,                   //翻页
PageUnCurl,                 //反翻页
CameraIrisHollowOpen,       //开镜头
CameraIrisHollowClose,      //关镜头
CurlDown,                   //下翻页
CurlUp,                     //上翻页
FlipFromLeft,               //左翻转
FlipFromRight,              //右翻转
} AnimationType;


switch (self.animationType) {

    case Fade:
        [self transitionWithType:kCATransitionFade  ForView:self.animationChangeView];
        break;

    case Push:
        [self transitionWithType:kCATransitionPush  ForView:self.animationChangeView];
        break;

    case Reveal:
        [self transitionWithType:kCATransitionReveal  ForView:self.animationChangeView];
        break;

    case MoveIn:
        [self transitionWithType:kCATransitionMoveIn  ForView:self.animationChangeView];
        break;

    case Cube:
        [self transitionWithType:@"cube"  ForView:self.animationChangeView];
        break;

    case SuckEffect:
        [self transitionWithType:@"suckEffect"  ForView:self.animationChangeView];
        break;

    case OglFlip:
        [self transitionWithType:@"oglFlip"  ForView:self.animationChangeView];
        break;

    case RippleEffect:
        [self transitionWithType:@"rippleEffect"  ForView:self.animationChangeView];
        break;

    case PageCurl:
        [self transitionWithType:@"pageCurl"  ForView:self.animationChangeView];
        break;

    case PageUnCurl:
        [self transitionWithType:@"pageUnCurl"  ForView:self.animationChangeView];
        break;

    case CameraIrisHollowOpen:
        [self transitionWithType:@"cameraIrisHollowOpen"  ForView:self.animationChangeView];
        break;

    case CameraIrisHollowClose:
        [self transitionWithType:@"cameraIrisHollowClose"  ForView:self.animationChangeView];
        break;
    case CurlDown:
        [self animationWithView:self.animationChangeView WithAnimationTransition:UIViewAnimationTransitionCurlDown];
        break;

    case CurlUp:
        [self animationWithView:self.animationChangeView WithAnimationTransition:UIViewAnimationTransitionCurlUp];
        break;

    case FlipFromLeft:
        [self animationWithView:self.animationChangeView WithAnimationTransition:UIViewAnimationTransitionFlipFromLeft];
        break;

    case FlipFromRight:
        [self animationWithView:self.animationChangeView WithAnimationTransition:UIViewAnimationTransitionFlipFromRight];

    default:
        break;
}

- (void) animationWithView : (UIView *)view WithAnimationTransition : (UIViewAnimationTransition) transition
{
[UIView animateWithDuration:self.speedTime?self.speedTime:0.6 animations:^{
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:transition forView:view cache:YES];
}];
}

-(void) transitionWithType:(NSString *) type ForView : (UIView *) view
{
//创建CATransition对象
CATransition *animation = [CATransition animation];
//设置运动时间
animation.duration = self.speedTime?self.speedTime:0.6;

//设置运动type
animation.type = type;

//设置子类
animation.subtype = self.newindex>self.oldindex?       kCATransitionFromLeft:kCATransitionFromRight;

//设置运动速度
animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;

[view.layer addAnimation:animation forKey:@"animation"];

 }
上一篇下一篇

猜你喜欢

热点阅读