Predicting UI element frames in -shouldAutorotateToInterfaceOrientation:
Asked Answered
A

2

6

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

That is, when building a frame for a specific subview, I want to set its frame relative to the available space between the navigation bar and the toolbar. To make it smooth, it's best to do this in shouldAutorotateToInterfaceOrientation: rather than didRotateFromInterfaceOrientation:, but values such as self.navigationController.toolbar.frame.size.height are different between orientations and devices.

I'd like to calculate my new subview frame against what the toolbar's thickness will be, and I'd like to do it without hardcoding values such as 32pt, 44pt, etc.

Any thoughts?

Amphibrach answered 5/5, 2011 at 9:14 Comment(0)
L
1

You should do all your frame resizing in willAnimateRotationToInterfaceOrientation:duration:

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

One way could be to do all the frames resizing in your code, including the toolbar. That way you have full control over the size of your UI elements.

Labyrinthine answered 12/10, 2011 at 7:37 Comment(0)
D
1

You can change your views frame in willAnimateRotationToInterfaceOrientation:duration: method.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];

    NSLog(@"%@", NSStringFromCGRect(self.navigationController.navigationBar.frame));
}

For more information take a look at the documentation provided by Apple.

Directive answered 20/8, 2011 at 5:56 Comment(0)
L
1

You should do all your frame resizing in willAnimateRotationToInterfaceOrientation:duration:

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

One way could be to do all the frames resizing in your code, including the toolbar. That way you have full control over the size of your UI elements.

Labyrinthine answered 12/10, 2011 at 7:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.