UITableView in UINavigationController falls under navigation bar after rotation

This is a portrait:

alt text

It's a landscape

alt text

I tried this on rotation unsuccessfully:

self.tableView.autoresizesSubviews = YES;
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
+3
source share
8 answers

. , , . / / . , , . , , , ( 44 32 , ). , willRotateToInterfaceOrientation didRotateFromInterfaceOrientation. . , willRotateToInterfaceOrientation:

CGRect frame = self.navViewController.navigationBar.frame;
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
    frame.size.height = 44;
} else {
    frame.size.height = 32;
}
self.navViewController.navigationBar.frame = frame;

, .

+13

root, , ( ). :

willRotateToInterfaceOrientation:duration:
willAnimateRotationToInterfaceOrientation:duration:
didRotateFromInterfaceOrientation:
willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
didAnimateFirstHalfOfRotationToInterfaceOrientation:
willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:

, , , – willAnimateRotationToInterfaceOrientation:duration: .

+7

didRotateFromInterfaceOrientation.

[self.navigationController.view layoutSubviews];

, .

+6

, @jstevenco . , , , , :

tableviewcontroller :

- (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;  

}

31.9 44.1 ! 32 44, , , , . , , - .

+2

, "willAnimateRotationToInterfaceOrientation:" , .

- :

        - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation];
// Your code here

    }
0

, . , , ( , , ), , .

0
source

When you change the orientation of the device your UINavigationControllershould receive a notification. This will not happen if you add viewin UINavigationControllerto another UIView.

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

0
source

Source: https://habr.com/ru/post/1725297/


All Articles