Predicting user interface elements in -shouldAutorotateToInterfaceOrientation:

Is it possible to request (programmatically, at runtime) what the height / thickness of the navigation bar and / or toolbar will be after rotation?

That is, when you create a frame for a specific subset, I want to set its frame relative to the available space between the navigation bar and the toolbar. To make it smooth, it is best to do this in shouldAutorotateToInterfaceOrientation: rather than didRotateFromInterfaceOrientation: but values ​​like self.navigationController.toolbar.frame.size.height differ between orientations and devices.

I would like to calculate my new subview framework with what will be the thickness of the toolbar, and I would like to do this without hardcoding values ​​like 32pt, 44pt, etc.

Any thoughts?

+6
source share
2 answers

You must make all frame size changes in willAnimateRotationToInterfaceOrientation:duration:

AFAIK there is no way to predict the size of your UIView until you reach didRotateFromInterfaceOrientation:

One way could be to change all the frames in the code, including the toolbar. This way you have full control over the size of the user interface elements.

+1
source

You can change the viewing frame in the willAnimateRotationToInterfaceOrientation:duration: method.

 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; NSLog(@"%@", NSStringFromCGRect(self.navigationController.navigationBar.frame)); } 

For more information, check out the documentation provided by Apple.

+1
source

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


All Articles