2016-07-03 2 views
0

채팅보기가 있으며보기의 높이를 변경하여 키보드로 textView를 전환합니다. 그러나 키보드 유형을 그림 이모티콘으로 변경하고 일반 키보드로 다시 변경하면 UIKeyboardWillShowNotification이 다시 실행되어 뷰를 추가로 위로 이동합니다 (즉, 키보드의 높이가 더 높아짐). 어떻게 이것을 추적 할 수 있고, 키보드의 높이를 뺀 것이 아닌지 확인하거나, 이모티콘 키보드의 높이를 뺄 수만 있다면 어떻게 할 수 있습니까? keyboardWillShow 이벤트가 추가 변경됩니다.

enter image description here

func keyboardWillShow(notification: NSNotification) { 
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() { 
     self.view.frame.size.height = self.view.frame.size.height - keyboardSize.height 
     self.view.layoutIfNeeded() 
    } 
} 
나는

enter image description here

내가 정상

다시 이모티콘에서 키보드를 변경하고 그림 이모티콘 키보드 변경

enter image description here

답변

1

self.view.frame.height를 사용하는 대신 화면 높이를 사용하십시오.

func keyboardWillShow(notification: NSNotification) { 
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() { 
    self.view.frame.size.height = UIScreen.mainScreen().bounds.size.height - keyboardSize.height 
    self.view.layoutIfNeeded() 
} 

}

이보다 더 간단한 방법은 자동으로 당신이 원하는 모든 것을 처리하는 코드

https://github.com/hackiftekhar/IQKeyboardManager

이 타사 유틸리티를 가져 오는 것입니다.

관련 문제