自定义过渡动画导致导航栏动画

时间:2015-06-02 18:51:19

标签: ios objective-c animation

我正在视图控制器之间实现自定义过渡动画,但出于某种原因,我的导航栏会随着过渡动画一起动画化。这是某种自动布局问题吗?我不确定它会是怎样的。 这是我用来显示和关闭具有自定义转换的视图控制器的代码。

我希望导航栏不会动画,任何想法为什么会发生这种情况?

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    // Grab the from and to view controllers from the context
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];



    if (self.presenting) {
        fromViewController.view.userInteractionEnabled = NO;

        [transitionContext.containerView addSubview:fromViewController.view];
        [transitionContext.containerView addSubview:toViewController.view];

        int frameHeight = fromViewController.view.frame.size.height;
        CGRect startFrame = fromViewController.view.frame;
        startFrame.origin.y = frameHeight;
        toViewController.view.frame = startFrame;

        //create a view with the same background color to cover up background on bounce effect
        UIView *bottomCover = [[UIView alloc]initWithFrame:CGRectMake(0, startFrame.size.height-30, startFrame.size.width, 30)];
        [bottomCover setBackgroundColor:[UIColor colorWithRed:0.956 green:0.962 blue:0.956 alpha:1]];
        [transitionContext.containerView insertSubview:bottomCover belowSubview:toViewController.view];

        __block CGRect endFrame = toViewController.view.frame;
        [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0 usingSpringWithDamping:.75 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
            endFrame.origin.y = 0;
            toViewController.view.frame = endFrame;
        } completion:^(BOOL finished) {
            [bottomCover removeFromSuperview];
            toViewController.view.frame = endFrame;
            [transitionContext completeTransition:YES];
        }];

    }
    else {
        toViewController.view.userInteractionEnabled = YES;

        [transitionContext.containerView addSubview:toViewController.view];
        [transitionContext.containerView addSubview:fromViewController.view];

        CGRect endFrame = toViewController.view.frame;
        endFrame.origin.y = 0;
        fromViewController.view.frame = endFrame;


        [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0 usingSpringWithDamping:.9 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseIn animations:^{

            int frameHeight = toViewController.view.frame.size.height;
            CGRect startFrame = fromViewController.view.frame;
            startFrame.origin.y = frameHeight;
            fromViewController.view.frame = startFrame;

        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
            //Because there is a bug in Xcode apparently.
            [[UIApplication sharedApplication].keyWindow addSubview:toViewController.view];
        }];

    }
}

0 个答案:

没有答案