Why does UIViewController extend under UINavigationBar, while UITableViewController doesn't?

前端 未结 3 602
庸人自扰
庸人自扰 2020-12-07 12:55

I have UITabbarController with UINavigationController in it. I have a subclass of UIView that I assign as the view of

相关标签:
3条回答
  • 2020-12-07 13:32

    @Gank's answer is correct, but the best place to do this is on the UINavigationControllerDelegate (if you have one):

    func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
        viewController.edgesForExtendedLayout = UIRectEdge.None
    }
    
    0 讨论(0)
  • 2020-12-07 13:35

    By default, UITableViewController's views are automatically inset in iOS7 so that they don't start below the navigation bar/status bar. This is controller by the "Adjust scroll view insets" setting on the Attributes Inspector tab of the UITableViewController in Interface Builder, or by the setAutomaticallyAdjustsScrollViewInsets: method of UIViewController.

    For a UIViewController's contents, if you don't want its view's contents to extend under the top/bottom bars, you can use the Extend Edges Under Top Bars/Under Bottom Bars settings in Interface Builder. This is accessible via the edgesForExtendedLayout property.

    0 讨论(0)
  • 2020-12-07 13:35

    Objective-C:

    - (void)viewDidLoad {
        [super viewDidLoad];
        self.edgesForExtendedLayout = UIRectEdgeNone;
     }
    

    Swift 2:

    self.edgesForExtendedLayout = UIRectEdge.None
    

    Swift 3+:

    self.edgesForExtendedLayout = []
    
    0 讨论(0)
提交回复
热议问题