Created
October 30, 2013 16:02
-
-
Save pingwinator/7235232 to your computer and use it in GitHub Desktop.
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
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardWillShown:) | |
name:UIKeyboardWillShowNotification object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardWillBeHidden:) | |
name:UIKeyboardWillHideNotification object:nil]; | |
} | |
- (void)keyboardWillBeHidden:(NSNotification*)aNotification | |
{ | |
if ([self respondsToSelector:@selector(preferredContentSize)]) { | |
self.preferredContentSize = CGSizeMake(320, 480); | |
} | |
} | |
- (void)keyboardWillShown:(NSNotification*)aNotification | |
{ | |
if (![self isPortraitOrientation] && [self respondsToSelector:@selector(preferredContentSize)]) { | |
self.preferredContentSize = CGSizeMake(320, 200); | |
} | |
} | |
- (BOOL) isPortraitOrientation { | |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; | |
if ( UIDeviceOrientationUnknown == orientation || UIDeviceOrientationFaceUp == orientation || UIDeviceOrientationFaceDown == orientation ) { | |
orientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation]; | |
} | |
return UIDeviceOrientationIsPortrait(orientation); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment