2015-04-20 90 views
1

由於iOS8上,許多thirdPart鍵盤表演,我想,當它顯示的iOS:獲取thirdPart鍵盤的正確高度

NSDictionary* info = [aNotification userInfo]; CGSize kbSize = 
[[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; 

不過,我可以得到系統鍵盤的高度,鍵盤的高度,但不能得到第三方密鑰(例如SouGouKeyboard),它返回0而不是如何獲得正確的高度?

返回: { UIKeyboardAnimationCurveUserInfoKey = 7; UIKeyboardAnimationDurationUserInfoKey = "0.25"; UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 0}}"; UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 568}"; UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 568}"; UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 0}}"; UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 568}, {320, 0}}"; }

+0

NSValue * keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey]。 – AnjDenny

+0

它返回:a通知的打印說明: NSConcreteNotification 0x17424f4b0 {name = UIKeyboardDidShowNotification; userInfo = {UI1} {UIKeyboardAnimationCurveUserInfoKey = 7; UIKeyboardAnimationDurationUserInfoKey =「0.25」; UIKeyboardBoundsUserInfoKey =「NSRect:{{0,0},{320,0}}」; UIKeyboardCenterBeginUserInfoKey =「NSPoint:{160,568}」; UIKeyboardCenterEndUserInfoKey =「NSPoint:{160,568}」; UIKeyboardFrameBeginUserInfoKey =「NSRect:{{0,568},{320,0}}」; UIKeyboardFrameEndUserInfoKey =「NSRect:{{0,568},{320,0}}」; }} – AdrianHor

回答

0

你可以試試這個方法

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:)name:UIKeyboardDidShowNotification  
    object:nil]; 

- (void)keyboardWasShown:(NSNotification *)notification 
{ 
    CGSize keyboardSize = [[[notification userInfo]objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 
    int height = MIN(keyboardSize.height,keyboardSize.width); 
    int width = MAX(keyboardSize.height,keyboardSize.width); 
}