iOS 7自定义Present转场与UINavigationController

7
我正在使用iOS 7自定义转场来呈现一个UINavigationController。但是有一个问题,当它在动画时,导航栏的大小只有44个点。然后在动画完成后,导航控制器发现有状态栏,所以会添加20个点用于状态栏。
我的问题是,在其进行动画时,是否有可能将导航栏设置为64个点,这样在完成动画后就不再改变了?
请在此处查看更多详细信息:自定义视图转换 这是我的自定义动画代码:
 - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{

    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    CGRect finalFrame = [transitionContext finalFrameForViewController:toViewController];

    UIView *containerView = [transitionContext containerView];

    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    toViewController.view.frame = CGRectOffset(finalFrame, 0, screenBounds.size.height);
    [containerView addSubview:toViewController.view];

    NSTimeInterval duration = [self transitionDuration:transitionContext];

    [UIView animateWithDuration:duration delay:0.0 usingSpringWithDamping:0.6 initialSpringVelocity:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
        toViewController.view.frame = finalFrame;
    } completion:^(BOOL finished) {
        [transitionContext completeTransition:YES];
    }];
}

更新:有人解决了这个问题,但是方法比较巧妙。在将toViewController.view添加到containerView后,请添加以下代码。
if ([toViewController isKindOfClass:[UINavigationController class]]) {
    UINavigationController* navigationController = (UINavigationController*) toViewController;
    UINavigationBar* bar = navigationController.navigationBar;
    CGRect frame = bar.frame;
    bar.frame = CGRectMake(frame.origin.x, frame.origin.y + 20.0f, frame.size.width, frame.size.height);
}

有更好的方法吗?


你的 from- view controller 显示状态栏吗?你的 to- view controller 显示状态栏吗? - bilobatum
1个回答

10

我曾经遇到过同样的问题,解决方法是在设置frame之前,先将toViewController添加到容器中。

请将这两行代码调换位置:

[containerView addSubview:toViewController.view];
toViewController.view.frame = CGRectOffset(finalFrame, 0, screenBounds.size.height);

1
哇,我花了很长时间搜索和尝试这个 - 真是太棒了! - t0PPy
太棒了!谢谢。 - hgwhittle

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接