【发布时间】: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