以自定义模式呈现UINavigationController

我试图从UINavigationController呈现一个UINavigationController。 我正在使用新的iOS 7 transitioningDelegate的东西,它的工作很好….除了导航栏开始高,然后在animation结束时收缩。 我假设它缩小,因为酒吧不接触屏幕的顶部,但为什么它开始高? 我能阻止这个吗?

注意吧开始高

这是animation代码:

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext { UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; UIView* containerView = [transitionContext containerView]; if (toViewController.isBeingPresented) { [self presentModalView:toViewController.view fromView:fromViewController.view inContainerView:containerView withTransitionContext:transitionContext]; } else { [self dismissModalView:fromViewController.view fromView:toViewController.view withTransitionContext:transitionContext]; } } - (void)presentModalView:(UIView*)modalView fromView:(UIView*)presentationView inContainerView:(UIView*)containerView withTransitionContext:(id<UIViewControllerContextTransitioning>)transitionContext { [containerView addSubview:modalView]; presentationView.userInteractionEnabled = NO; modalView.layer.cornerRadius = 5; modalView.clipsToBounds = YES; CGRect finalFrame = CGRectInset(presentationView.frame, 10, 20); modalView.frame = CGRectOffset(finalFrame, 0, CGRectGetHeight(presentationView.frame)); [UIView animateWithDuration:animationDuration animations:^{ modalView.frame = finalFrame; presentationView.alpha = 0.2; } completion:^(BOOL finished) { [transitionContext completeTransition:YES]; }]; } 

我有这个问题的解决scheme。

http://blog.jaredsinclair.com/post/61507315630/wrestling-with-status-bars-and-navigation-bars-on-ios-7 ,编号4:

UINavigationController会将其UINavigationBar的高度更改为44点或64点,这取决于一个相当奇怪的和没有logging的约束。 如果UINavigationController检测到其视图的顶部与UIWindow的顶部相邻,则绘制其导航栏,高度为64点。 如果它的视图的顶端与UIWindow的顶端不相连(即使只closures一个点),那么它以44的高度以“传统”方式绘制其导航栏。 即使在应用程序的视图控制器层次结构中存在多个子项,UINavigationController也会执行此逻辑。 没有办法阻止这种行为。

因此,你的问题是, UINavigationController检测到它的视图的框架在animation开始的时候和UIWindow的顶部是连续的。 这是因为当你添加modalView作为containerView的子视图时,modalView的框架是{0,0,0,0}。 因为这个框架与UIWindow的顶部在视觉上是连续的,所以UINavigationController以64点的高度绘制它的UINavigationBar 。 当animation完成时,导航控制器的新框架不再与窗口顶部连续,并且绘制高度为44的导航栏。

一种解决方法是在设置框架后,将导航控制器的视图添加到容器视图。 像这样,

  - (void)presentModalView:(UIView*)modalView fromView:(UIView*)presentationView inContainerView:(UIView*)containerView withTransitionContext:(id<UIViewControllerContextTransitioning>)transitionContext { presentationView.userInteractionEnabled = NO; modalView.layer.cornerRadius = 5; modalView.clipsToBounds = YES; CGRect finalFrame = CGRectInset(presentationView.frame, 10, 20); modalView.frame = CGRectOffset(finalFrame, 0, CGRectGetHeight(presentationView.frame)); [containerView addSubview:modalView]; [UIView animateWithDuration:animationDuration animations:^{ modalView.frame = finalFrame; presentationView.alpha = 0.2; } completion:^(BOOL finished) { [transitionContext completeTransition:YES]; }]; } 

这应该可以解决你的问题,因为导航栏总是在整个animation中以44点的高度绘制。 我不知道一种方法来保持导航栏64点的高度,因为这将涉及愚弄导航控制器认为它是与窗口的顶部连续。