Skip to content

Instantly share code, notes, and snippets.

@ikarius
Created March 24, 2011 09:10
Show Gist options
  • Save ikarius/884777 to your computer and use it in GitHub Desktop.
Save ikarius/884777 to your computer and use it in GitHub Desktop.
Simple (but effecive) workaround for dynamic AND selective orientation change in a UI(View|TabBar|Navigation)Controller
/* Selective / dynamic UI orientation
Simply add this method (updateOrientation) to your class and call it in:
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateOrientation];
}
...
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
[self updateOrientation];
return YES;
}
*/
// Huge hack ! Thanks to: http://goodliffe.blogspot.com/2009/12/iphone-forcing-uiview-to-reorientate.html
-(void)updateOrientation
{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
[view removeFromSuperview];
[window addSubview:view];
[window bringSubviewToFront:self.view];
[window makeKeyWindow]; // Don't forget to !
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment