当StatusBar更改时,目标C导航栏不会调整

时间:2016-09-20 19:47:24

标签: objective-c iphone uinavigationcontroller uinavigationbar uistatusbar

我们遇到一个问题,用户在iPhone上使用我们的应用程序,并在rootviewcontroller呈现的视图上接收呼叫,并覆盖导航控制器及其导航栏。呼叫的状态栏显示并按下当前视图,但当从超视图中删除该视图时,状态栏覆盖导航栏的一半。

我们尝试在app委托中使用UIApplicationWillChangeStatusBarFrameNotification,然后调整导航控制器和导航栏的大小无效。我们还尝试在显示视图的页面的viewWillAppear函数中重置导航控制器和导航栏的框架。

谁能告诉我们哪里出错了?

在App Delegate中,我们尝试了这个

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self setupAppStyles];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor ugBlue];
UINavigationController *navController = [[UINavigationController alloc] init];
self.window.rootViewController = navController;

[self.window makeKeyAndVisible];

[self setUpNotifications];

return YES; }

-(void) setUpNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(statusFrameChanged:)
                                             name:UIApplicationWillChangeStatusBarFrameNotification
                                           object:nil];}

- (void)statusFrameChanged:(NSNotification*)note {
CGRect statusBarFrame = [note.userInfo[UIApplicationStatusBarFrameUserInfoKey] CGRectValue];
self.statusHeight = statusBarFrame.size.height;

UIScreen *screen = [UIScreen mainScreen];
CGRect viewRect = screen.bounds;

viewRect.size.height -= self.statusHeight;
viewRect.origin.y += self.statusHeight;

[[UINavigationBar appearance] setFrame:viewRect];

NSLog(@"The status frame has changed");

//[self.navController.view setFrame:viewRect];


self.navController.view.frame.size.height);}

我们还在视图中尝试了类似的东西viewWillAppear函数也没有积极的结果。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我们能够解决这个问题。在调用presentViewController的视图的viewDidAppear中我们放了

   CGRect screenRect = [[UIScreen mainScreen] bounds];
   CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height;
   CGRect frame = CGRectMake(0.0f, statusSize, screenRect.size.width, navBarHeight);
   [self.navigationController.navigationBar setFrame:frame];

显示状态栏时