倒塌的键盘,工具栏

问题描述:

collapsed keyboard倒塌的键盘,工具栏

如何检查时,尽显键盘和折叠像这样的时候?也许我可以检查它的高度?

我检查userInfonotification现在,我发现没有什么有用的解决我的问题。

只需订阅通知:

NotificationCenter.default.addObserver(self, selector: 
#selector(self.adjustForKeyboard), name: 
NSNotification.Name.UIKeyboardDidShow, object: nil) 

NotificationCenter.default.addObserver(self, selector: 
#selector(self.adjustForKeyboard), name: 
NSNotification.Name.UIKeyboardDidHide, object: nil) 

并粘贴下一个方法了近

func adjustForKeyboard(notification: NSNotification) { 
    let userInfo = notification.userInfo! 

    if let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue { 
     let keyboardViewEndFrame = delegate.getView().convert(keyboardScreenEndFrame, from: delegate.getView().window) 

     var customInset = UIEdgeInsets.zero    
     if notification.name == NSNotification.Name.UIKeyboardDidHide { 
      customInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) 
     } else { 
      customInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardViewEndFrame.height, right: 0) 
     } 

     scrollView.contentInset = customInset 
     scrollView.scrollIndicatorInsets = customInset 
    } 
} 

不要忘了,当你离开这个VC

NotificationCenter.default.removeObserver(self) 
删除观察者