IOS development-get the ios keyboard height
-(Void) viewDidLoad {[super viewDidLoad]; // adds a listener to receive messages when the keyboard appears or changes
[[Nsicationcenter center defacenter center] addObserver: self
Selector: @ selector (keyboardDidShow :)
Name: UIKeyboardWillShowNotification
Object: nil];
// Adds a listener to receive messages when the key exits.
[[Nsicationcenter center defacenter center] addObserver: self
Selector: @ selector (keyboardDidHide :)
Name: UIKeyboardWillHideNotification
Object: nil];
}
// Called when the keyboard appears or changes
-(Void) keyboardDidShow :( NSNotification *) notification {
NSDictionary * userInfo = [notification userInfo];
CGSize keyboardSize = [[userInfo objectForKey: UIKeyboardFrameBeginUserInfoKey] CGRectValue]. size;
_ KeyBoardHeight = keyboardSize. height;
[Self changeViewYByShow];
}
// Called when the keyboard is hidden
-(Void) keyboardDidHide :( NSNotification *) notification {
_ KeyBoardHeight = 0;
[Self changeViewYByHide];
}
# Pragma mark-private methods
-(Void) changeViewYByShow {
[UIView animateWithDuration: 0.2 animations: ^ {
CGRect rect = self. view. frame;
Rect. origin. y-= self. keyBoardHeight;
Self. view. frame = rect;
}];
}
-(Void) changeViewYByHide {
CGRect rect = self. view. frame;
Rect. origin. y = 64;
Self. view. frame = rect;
}