Skip to content

Instantly share code, notes, and snippets.

@pingwinator
Created October 30, 2013 16:02
Show Gist options
  • Save pingwinator/7235232 to your computer and use it in GitHub Desktop.
Save pingwinator/7235232 to your computer and use it in GitHub Desktop.
- (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