$ P $在自定义模式psenting一个UINavigationController [英] Presenting a UINavigationController in a custom modal
问题描述
我想present从一个UINavigationController一个UINavigationController。我使用的是全新的iOS 7 transitioningDelegate的东西,它的伟大的工作,除了....导航栏开始时高,然后在动画结束收缩。我假设它缩小,因为酒吧不接触屏幕的顶部,但它为什么开始就高吗?我可以prevent呢?
下面是动画code:
- (无效)animateTransition:(ID< UIViewControllerContextTransitioning>){transitionContext *的UIViewController = fromViewController [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
*的UIViewController = toViewController [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView的* containerView = [transitionContext containerView] 如果(toViewController.isBeing presented){
[自presentModalView:toViewController.view fromView:fromViewController.view inContainerView:containerView withTransitionContext:transitionContext];
}其他{
[个体经营dismissModalView:fromViewController.view fromView:toViewController.view withTransitionContext:transitionContext];
}
} - (无效)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动画:^ {
modalView.frame = finalFrame;
presentationView.alpha = 0.2;
}完成:^(BOOL完){
[transitionContext completeTransition:YES];
}];
}
我有一个解决这个问题。
从<一个href=\"http://blog.jaredsinclair.com/post/61507315630/wrestling-with-status-bars-and-navigation-bars-on-ios-7\" rel=\"nofollow\">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的执行,即使它是降低应用程序的视图控制器层次里面好几个孩子。有没有办法为prevent这一行为。
块引用>您的问题,因此,是,
绘制导航栏的UINavigationController
正在检测,它的视图的框架是连续与的UIWindow
顶级的动画开始。这是由于这样的事实,当你添加了modalView
为containerView
时,该modalView帧的子视图为{0,0,0,0}。因为这个框架将与的UIWindow
顶级视觉上连续,在的UINavigationController
绘制其UINavigationBar的
与64点的高度。当动画完成导航控制器的新的帧是不再与顶窗户连续的,并将它与44的高度一种解决方案是在导航控制器的视图添加到容器视图后设置它的框架。像这样,
- (无效)presentModalView:(UIView的*)modalView fromView:(UIView的*)presentationView inContainerView:(UIView的*)containerView withTransitionContext:(ID&LT; UIViewControllerContextTransitioning&GT; )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动画:^ {
modalView.frame = finalFrame;
presentationView.alpha = 0.2;
}完成:^(BOOL完){
[transitionContext completeTransition:YES];
}];
}这应该解决您的问题,在导航栏将始终以44分在整个动画的高度绘制。我不知道的方式,让导航栏64点的高度,因为这将涉及到导航控制器欺骗,以为它是连续的窗口的顶部。
I'm trying to present a UINavigationController from a UINavigationController. I'm using the new iOS 7 transitioningDelegate stuff and it's working great.... except the navigation bar starts out tall and then shrinks when the animation is over. I'm assuming it shrinks because the bar doesn't touch the top of the screen, but why does it start out tall? Can I prevent this?
Here's the animation code:
- (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]; }]; }
解决方案I have a solution to this problem.
From http://blog.jaredsinclair.com/post/61507315630/wrestling-with-status-bars-and-navigation-bars-on-ios-7, number 4:
UINavigationController will alter the height of its UINavigationBar to either 44 points or 64 points, depending on a rather strange and undocumented set of constraints. If the UINavigationController detects that the top of its view’s frame is visually contiguous with its UIWindow’s top, then it draws its navigation bar with a height of 64 points. If its view’s top is not contiguous with the UIWindow’s top (even if off by only one point), then it draws its navigation bar in the "traditional" way with a height of 44 points. This logic is performed by UINavigationController even if it is several children down inside the view controller hierarchy of your application. There is no way to prevent this behavior.
Your problem, therefore, is that the
UINavigationController
is detecting that its view's frame is contiguous with theUIWindow
's top at the beginning of the animation. This is due to the fact that when you added themodalView
as a subview of thecontainerView
, the frame of the modalView is {0,0,0,0}. Because this frame would be visually contiguous with theUIWindow
's top, theUINavigationController
draws itsUINavigationBar
with a height of 64 points. When the animation is completed the new frame of the navigation controller is no longer continuous with the windows top, and it draws the navigation bar with a height of 44.One solution is to add the navigation controller's view to the container view AFTER setting it's frame. Like so,
- (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]; }]; }
That should solve your problem, in that the navigation bar will always be drawn with a height of 44 points throughout the animation. I don't know of a way to keep the height of the navigation bar 64 points, because that would involve fooling the navigation controller into thinking it was contiguous with the top of the window.
这篇关于$ P $在自定义模式psenting一个UINavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!