UITableView in UINavigationController gets under Navigation Bar after rotation

前端 未结 8 818
清酒与你
清酒与你 2020-12-21 06:10

This is Portrait:

This is Landscape

I\'ve tried this on rotation with no success:

self.tableView.autoresizesSubviews = YE         


        
相关标签:
8条回答
  • 2020-12-21 07:03

    Your UINavigationController needs to get notified when the device orientation changes. This doesn't happen if you only add the view of a UINavigationController to another UIView.

    Starting with iOS 5, you can simply call addChildViewController: on the parent UIViewController, which will ensure that orientation changes are propagated to this child view controller.

    0 讨论(0)
  • 2020-12-21 07:09

    I have exactly the same issue, and @jstevenco led me to a really strange solution. My views also auto resize on rotation, but the tableview doesn't seem to understand there is a navigationcontroller sitting there:

    Within the tableviewcontroller, add the following:

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    {
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
     CGRect frame = navBar.frame;
    if (fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        frame.size.height = 31.9;
    } else {
        frame.size.height = 44.1;
    }
    navBar.frame = frame;  
    
    }
    

    The 31.9 and 44.1 are very important strangly! Leaving these are 32 and 44, there is no resizing to do, so it seems to ignore it. Worked for me, hope it helps someone else.

    0 讨论(0)
提交回复
热议问题