美文网首页
PUSH 转场动画

PUSH 转场动画

作者: runningLigg | 来源:发表于2016-07-07 15:07 被阅读0次

    从左向右的push转场动画

    - (void)animateTransition:(id)transitionContext {

    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    UIView *containerView = transitionContext.containerView;

    UIView *fromView;

    UIView *toView;

    if ([transitionContext respondsToSelector:@selector(viewForKey:)]) {

    fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];

    toView = [transitionContext viewForKey:UITransitionContextToViewKey];

    } else {

    fromView = fromViewController.view;

    toView = toViewController.view;

    }

    [containerView addSubview:toView];

    if ([toViewController isKindOfClass:[OneViewController class]]) {

    fromView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

    toView.frame = CGRectMake(-[UIScreen mainScreen].bounds.size.width, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

    }else {

    fromView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

    toView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

    }

    [containerView addSubview:toView];

    NSTimeInterval transitionDuration = [self transitionDuration:transitionContext];

    [UIView animateWithDuration:transitionDuration animations:^{

    if ([toViewController isKindOfClass:[OneViewController class]]) {

    fromView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

    toView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

    }else {

    fromView.frame = CGRectMake(-[UIScreen mainScreen].bounds.size.width, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

    toView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

    }

    } completion:^(BOOL finished) {

    //告诉转场上下文,动画是否完成

    BOOL wasCancelled = [transitionContext transitionWasCancelled];

    [transitionContext completeTransition:!wasCancelled];

    }];

    }

    相关文章

      网友评论

          本文标题:PUSH 转场动画

          本文链接:https://www.haomeiwen.com/subject/pbdljttx.html