gpt4 book ai didi

iPhone - 关闭模态视图 Controller 后 - 页面顶部留有空隙

转载 作者:太空狗 更新时间:2023-10-30 03:11:28 26 4
gpt4 key购买 nike

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

所以我有:

- (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 关闭模态视图 Controller 。

这一切都有效,当模式被关闭时,导航 Controller 中的 View 是可见的,其导航项标题位于顶部....

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

最佳答案

我遇到了同样的问题。我的解决方案是在切换 View 之前暂时关闭状态栏:

- (void) temporarilyHideStatusBar {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self performSelector:@selector(showStatusBar) withObject:nil afterDelay:0];
}
- (void) showStatusBar {
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}

// Use these by calling the hide function just before a broken view switch:
[self temporarilyHideStatusBar];
[self doViewSwitch];

// No need to call [self showStatusBar]; explicitly.

我尝试了其他基于代码的解决方案,我最喜欢这个,因为它在 100% 的时间都有效——我的一些基于框架的解决方案只在大部分时间有效——而且因为它具有最小的用户可见效果。

我怀疑这是一个 Apple 错误,很高兴听到他们关于最佳解决方法的官方说法。

关于iPhone - 关闭模态视图 Controller 后 - 页面顶部留有空隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1272912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com