【发布时间】:2015-07-31 12:02:34
【问题描述】:
我通过 containment 使 UINavigationController 成为另一个视图控制器的子节点。一切正常,除了在打开 通话状态栏 的情况下启动应用程序,然后在应用程序 UI 显示在屏幕上后将其切换回关闭时发生的一个奇怪问题。出现奇怪的黑色差距来代替状态栏。
请考虑下面的自包含示例应用程序:
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)opt
{
// Content
UILabel * aLbl = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 200, 40)];
aLbl.text = @"In-call status bar issue";
UIViewController * aContent = [[UIViewController alloc] init];
aContent.title = @"Title";
aContent.view.backgroundColor = UIColor.whiteColor;
[aContent.view addSubview:aLbl];
UINavigationController * aNav = [[UINavigationController alloc]
initWithRootViewController:aContent];
// Parentmost view controller containing the navigation view controller
UIViewController * aParent = [[UIViewController alloc] init];
[aParent.view addSubview:aNav.view];
[aParent addChildViewController:aNav];
[aNav didMoveToParentViewController:aParent];
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
self.window.rootViewController = aParent;
[self.window makeKeyAndVisible];
return YES;
}
@end
int main(int argc, char ** argv)
{ @autoreleasepool { return UIApplicationMain(argc, argv, nil, @"AppDelegate"); } }
重现问题的最简单方法是:
- 启动 iOS 模拟器。
- 按⌘+ y打开呼叫状态栏。状态栏会变宽和绿色。
- 手动启动应用程序并等待导航控制器出现。
- 再次按⌘+ y关闭呼叫状态栏。
用户界面现在应该如下所示:
任何人都知道如何解决问题?
【问题讨论】:
-
您是否尝试将尺寸等级或自动调整大小的掩码设置为
UINavigationContorller的视图?因为您的应用程序的UIWindow的大小调整应该是开箱即用的。所以我怀疑问题出在导航控制器的UIView上。 -
我能够重现 OP 所描述的问题。在应用程序启动后切换通话状态栏会导致预期的行为,但如果应用程序在通话状态栏打开后启动,则关闭通话状态栏将导致黑条。
-
我也刚在iOS设备上试了一下,问题又重现了,所以好像不是模拟器特有的。
-
@akivajgordon:不,这绝对不是模拟器特有的。我提到模拟器只是因为它是重现问题的最简单方法。
-
非常好的问题。根据您的指示,我很容易重现了这种现象。如果只有每个人都会以这种方式提问! span>
标签: ios uiviewcontroller uinavigationcontroller statusbar