iOS 7 | Navigation bar / Toolbar buttons very close to status bar

前端 未结 6 1005
太阳男子
太阳男子 2020-11-29 17:49

I have a problem when dragging a navigation bar or toolbar (storyboard) to my view controller.

UINavigationBar:

6条回答
  •  伪装坚强ぢ
    2020-11-29 18:11

    Please see my answer here, I've copied the content below for convenience:

    https://stackoverflow.com/a/18912291/1162959

    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.

提交回复
热议问题