【问题标题】:Objective C Navigation Bar does not adjust when StatusBar changes当 StatusBar 发生变化时,Objective C Navigation Bar 不会调整
【发布时间】:2017-01-28 21:09:25
【问题描述】:

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

我们尝试在应用程序委托中使用 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 函数中尝试了类似的方法,但也没有积极的结果。有什么想法吗?

【问题讨论】:

    标签: objective-c iphone uinavigationcontroller uinavigationbar uistatusbar


    【解决方案1】:

    我们能够解决这个问题。在调用 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];
    

    当状态栏显示时

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      • 1970-01-01
      • 2017-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-02
      相关资源
      最近更新 更多