2014-09-23 19 views
7

Tôi có một giao diện người dùng cần một số điều chỉnh vị trí khi bàn phím được hiển thị.iOS8 UIKeyboardWillShowNotification Chiều cao bàn phím của bên thứ ba

Sau đây được sử dụng để phát hiện khi một bàn phím được hiển thị:

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(keyboardWillShow:) 
              name:UIKeyboardWillShowNotification 
              object:nil]; 

Lưu ý: Tôi đã thử với cả hai UIKeyboardWillShowNotification và UIKeyboardDidShowNotification

- (void)keyboardWillShow:(NSNotification *)n { 
    if (isKeyboardShowing) 
    return; 

NSDictionary* userInfo = [n userInfo]; 

// get the size of the keyboard 
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 


// Animate keyboard shift 
[self.view layoutIfNeeded]; 

[UIView animateWithDuration:0.2f animations:^{ 
    // some animation here 
} completion:^(BOOL finished) { 
    if (finished) 
     isKeyboardShowing = YES; 
}]; 

Đối với tùy chỉnh bàn phím trở về kích thước bàn phím {320 , 0}. Vì bàn phím có thể có chiều cao khác nhau, tôi không thể có giá trị tĩnh để thay đổi giao diện người dùng khi bàn phím được hiển thị.

Đây có phải là sự cố với ios8 không? và có phương pháp nào khác để tự động nhận chiều cao bàn phím không?

Edit: Đây là UserInfo Dict:

{name = UIKeyboardDidShowNotification; userInfo = { 
    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}}"; 
}} 

Cảm ơn trước.

Trả lời

11

Sử dụng

CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; 

để có được kích thước thực tế của bàn phím

Các vấn đề liên quan