views:

745

answers:

1

I want to design a view/view controler that automaticaly shows/hides a subview when in landscape orientation. I want the subview to dissapear completely and other subviews to take up its space.

Using a UIViewController, I wrote code that sets the subviews' frame property and call it on:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration;

This solves the problem most of the times but has problems when the orientation change is happening when the view is not appearing. to bypass this, I am also calling the resizing method on:

- (void)viewWillAppear:(BOOL)animated;

but this has problems in some rare cases (involving a UISearchDisplayController) so I am also calling the resizing method on

- (void)viewDidAppear:(BOOL)animated;

As you can understand, I am unhappy with this code and I am looking for a better/more performant way to do this.

Any ideas?

+1  A: 

Inside

- (void)didRotateFromInterfaceOrientation:
    (UIInterfaceOrientation)fromInterfaceOrientation

To hide it

sub_view.hidden = YES;

To show it again

sub_view.hidden = NO;
Tuomas Pelkonen
thank you for your response but the hidden property just hides the view. It doesn't resize other views to take up its space.
Panagiotis Korros
Oh, you want to do that. Have you checked if you could use layoutSubviews and layoutIfNeeded?
Tuomas Pelkonen