繁体   English   中英

使用UINavigationController进行iOS 7自定义当前转换

[英]iOS 7 Custom Present Transition with UINavigationController

我正在使用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];
    }];
}

更新:有人解决了这个问题。 但非常hacky。 将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);
}

有更好的方法吗?

我有同样的问题,并解决了在设置此框架之前将t​​oViewController添加到容器。

反转如下的行:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM