L. Kvri
L. Kvri

Reputation: 1713

iOS best way to change the UI when orientation is changed

Which is the best way to change the UI when orientation is changed?

For example, use two different UIView one portrait and a landscape and show one of both if orientation is changed, or use one UIView and change the UI control sizes and positions?

Any other ideas?

Upvotes: 2

Views: 4443

Answers (2)

Markus Persson
Markus Persson

Reputation: 1093

I always recommend using the autoresizingmask for all the subviews in the view controller view. With this being set correctly all the views will resize automatically from the orientation and you don't need the extra rotation specific subviews (one portrait view and one landscape view).

Upvotes: 2

Mick MacCallum
Mick MacCallum

Reputation: 130193

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        NSLog(@"Change to custom UI for landscape");
    }
    else if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||
        toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        NSLog(@"Change to custom UI for portrait");

    }
}

Upvotes: 5

Related Questions