나는 또한 동일한 문제를 가지고 있으며 일부 변경 작업을 통해 잘 작동합니다. 시나리오에서 코드 아래 시도하고 볼이 작동하는 경우 :
@objc func keyboardWasShown(_ notification:NSNotification) {
var keyboardHeight: CGFloat = 260
var userinfo = notification.userInfo!
let keyboardSize = (userinfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
if keyboardSize!.height > 10.0{
keyboardHeight = keyboardSize!.height
}
let edgeInsects = UIEdgeInsetsMake(0, 0, keyboardHeight + 10, 0)
self.scrollView.contentInset = edgeInsects
self.scrollView.scrollIndicatorInsets = edgeInsects
// active text field
var aRect:CGRect = self.view.frame
aRect.size.height -= kbRectSize.height
if(!aRect.contains(activeField.frame.origin)){
scrollView.isScrollEnabled = true
scrollView.scrollRectToVisible(activeField.frame, animated: true)
aRect = CGRect.zero
}
}
내가 가입 화면 내 프로젝트에 코드 아래 사용하고 완벽하게 잘 작동 :
func keyboardWasShown(notification: NSNotification){
//Need to calculate keyboard exact size due to Apple suggestions
var keyboardHeight: CGFloat = 260
self.scrollView.isScrollEnabled = true
var info = notification.userInfo!
let keyboardSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
if keyboardSize!.height > 10.0{
keyboardHeight = keyboardSize!.height
}
let contentInsets : UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardHeight, 0.0)
self.scrollView.contentInset = contentInsets
self.scrollView.scrollIndicatorInsets = contentInsets
var aRect : CGRect = self.view.frame
aRect.size.height -= keyboardHeight
if let activeField = self.activeField {
if (!aRect.contains(activeField.frame.origin)){
self.scrollView.scrollRectToVisible(activeField.frame, animated: true)
}
}
}
func keyboardWillBeHidden(notification: NSNotification){
//Once keyboard disappears, restore original positions
self.scrollView.contentInset = UIEdgeInsets.zero
self.scrollView.scrollIndicatorInsets = UIEdgeInsets.zero
self.scrollView.isScrollEnabled = false
}
그냥 시도하고 디버그와 귀하의 요구 사항에 따라 더 많은 변화가 있습니다. 희망이 작동합니다. 키보드 알림 사용자 정보 사전의 값 쌍 - 찾을 수
는 참조 - https://developer.apple.com/library/content/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html#//apple_ref/doc/uid/TP40009542-CH5-SW7 – user1046037