我正在尝试从 UINavigationController 呈现 UINavigationController。我正在使用新的 iOS 7 transitioningDelegate 东西,它工作得很好......除了导航栏开始时很高,然后在动画结束时缩小。我假设它缩小了,因为条形图没有接触屏幕顶部,但为什么它一开始就很高呢?我可以阻止这种情况吗?
这是动画代码:
- (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];
}];
}
我有一个解决这个问题的方法。
From http://blog.jaredsinclair.com/post/61507315630/wrestling-with-status-bars-and-navigation-bars-on-ios-7,第 4 号:
UINavigationController 会将其 UINavigationBar 的高度更改为 44 点或 64 点,具体取决于一组相当奇怪且未记录的约束。如果 UINavigationController 检测到其视图框架的顶部与其 UIWindow 的顶部在视觉上是连续的,那么它会绘制高度为 64 点的导航栏。如果其视图的顶部与 UIWindow 的顶部不连续(即使仅偏离一点),则它将以“传统”方式绘制导航栏,高度为 44 点。此逻辑由 UINavigationController 执行,即使它是应用程序视图控制器层次结构内部的多个子级。没有办法阻止这种行为。
因此,你的问题是UINavigationController
正在检测其视图的框架与UIWindow
位于动画开头的顶部。这是因为当您添加modalView
作为子视图containerView
,modalView的frame为{0,0,0,0}。因为该框架在视觉上与UIWindow
的顶部,UINavigationController
绘制其UINavigationBar
高度为64点。动画完成后,导航控制器的新框架不再与窗口顶部连续,并绘制高度为 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];
}];
}
这应该可以解决您的问题,因为在整个动画中导航栏始终以 44 点的高度绘制。我不知道有什么方法可以将导航栏的高度保持在 64 点,因为这会欺骗导航控制器,使其认为它与窗口顶部相邻。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)