iPhone - 关闭模态视图控制器后 - 页面顶部留有间隙 [英] IPhone - After dismissing Modal View Controller - gap is left at top of page

查看:28
本文介绍了iPhone - 关闭模态视图控制器后 - 页面顶部留有间隙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动应用程序时,如果用户没有存储登录信息,我想显示一个模式视图控制器来强制输入此信息.我通过反复试验发现,这必须发生在我的根视图控制器的 viewDidAppear 中.我试图将它放在 viewDidLoad 和 viewWillAppear 中,但除非我将根视图控制器的视图分配给模态中使用的导航控制器的视图,否则这些都不起作用,这会导致其他问题...

When starting the app, if the user doesn't have login information stored, I want to display a modal view controller to force the entry of this information. I found through trial and error, that this had to occur in viewDidAppear of my root view controller. I tried to put it in viewDidLoad and viewWillAppear, but those didn't work unless I assigned the view of the root view controller to the view of the navigation controller used in the modal which then caused other issues...

所以我有:

- (void)viewDidAppear:(BOOL)animated
{
     NewAccountViewController *newAccountViewController = [[[NewAccountViewController alloc] initWithNibName:@"NewAccountViewController" bundle:nil] autorelease];

     UINavigationController *accountNavigationController = [[UINavigationController alloc] initWithRootViewController:newAccountViewController];
  [self presentModalViewController:accountNavigationController animated:YES];       
}

在 newAccountViewController 中,我有一个简单的导航项按钮,可以使用dismissModalViewController 关闭模态视图控制器.

And in the newAccountViewController I have a simple navigation item button that dismisses the modal view controller with dismissModalViewController.

这一切都有效,当模式被关闭时,导航控制器中的视图可见,其导航项标题位于顶部....

This all works and when the modal is dismissed a view in a navigation controller is visible with its navigation item title at the top....

但是在状态栏和蓝色导航项栏的顶部之间有一个和状态栏差不多大小的白色间隙.如果我不做模态,那么差距永远不会存在.它仅在模态显示和关闭后发生.我试过在 present 和 dismissModalViewController 上做动画:NO.我也尝试过不在模态中使用导航控制器,但也没有用.任何想法都会很棒!谢谢.

But there is a white gap about the same size as the status bar between the status bar and the top of the blue navigation item bar. If I don't do the modal, then the gap is never there. It only occurs after the modal is presented and dismissed. I've tried doing animated:NO on both the present and dismissModalViewController. I've also tried not using the navigation controller in the modal, and that did nothing as well. Any ideas would be great! Thanks.

推荐答案

原来这是因为我在当前视图控制器上调用了我的 modalviewcontroller,但我的视图控制器已经有另一个视图控制器加载为子视图.一旦我将其更改为在子视图中创建视图控制器,加载模式,然后它就消失了.感谢您的所有帮助.

Turns out this was happening because I was calling my modalviewcontroller on the current view controller, but my view controller already had a another view controller loaded as a subview. Once I changed it to make the view controller in the subview, load the modal, then it went away. Thanks for all your help.

这篇关于iPhone - 关闭模态视图控制器后 - 页面顶部留有间隙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆