public

Get keyboard height from an NSNotification

  • Download Gist
(deprecated)UINotificationKeyboardHeight.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14
@implementation NSNotification (KeyboardHeight)
 
- (CGFloat)keyboardHeight {
CGRect bounds;
NSValue *boundsValue = [self.userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
if (boundsValue) {
[boundsValue getValue:&bounds];
return bounds.size.height;
} else {
return 0;
}
}
 
@end
UINotification+KeyboardHeight.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14
@implementation NSNotification (KeyboardHeight)
 
- (CGFloat)keyboardHeight {
CGRect bounds;
NSValue *boundsValue = [self.userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
if (boundsValue) {
[boundsValue getValue:&bounds];
return bounds.size.height;
} else {
return 0;
}
}
 
@end
UINotificationKeyboardHeight.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14
@implementation NSNotification (KeyboardHeight)
 
- (CGFloat)keyboardHeight {
CGRect startFrame;
NSValue *startFrameValue = [self.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
if (startFrameValue) {
[startFrameValue getValue:&startFrame];
return startFrame.size.height;
} else {
return 0;
}
}
 
@end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.