问题描述
我想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];
}];
}
我有一个解决这个问题。
从http://blog.jaredsinclair.com/post/61507315630/wrestling-with-status-bars-and-navigation-bars-on-ios-7, 4号:
Your problem, therefore, is that the UINavigationController
is detecting that its view's frame is contiguous with the UIWindow
's top at the beginning of the animation. This is due to the fact that when you added the modalView
as a subview of the containerView
, the frame of the modalView is {0,0,0,0}. Because this frame would be visually contiguous with the UIWindow
's top, the UINavigationController
draws its UINavigationBar
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!