Created
March 24, 2011 09:10
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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