how to present a view controller on iOS7 without the status bar overlapping

后端 未结 4 1048
闹比i
闹比i 2020-12-13 00:57

I\'m seeing when I migrated my app to iOS 7, the nav bar is appearing under the status bar when presenting a view controller. I think a lot of people have run into this same

4条回答
  •  醉梦人生
    2020-12-13 01:20

    The easiest workaround I've found is to wrap the view controller you want to present inside a navigation controller, and then present that navigation controller.

    MyViewController *vc = [MyViewController new];
    UINavigationController *nav = [[UINavigationController alloc] 
        initWithRootViewController:vc];
    [self presentViewController:nav animated:YES completion:NULL];
    

    Advantages:

    • No mucking with frames needed.
    • Same code works on iOS 6 an iOS 7.
    • Less ugly than the other workarounds.

    Disadvantages:

    • You'll probably want to leave your XIB empty of navigation bars or toolbars, and programatically add UIBarButtonItems to the navigation bar. Fortunately this is pretty easy.

提交回复
热议问题