问题
Hope you are doing well!
I have a used IQKeyboardManager library in a project and I have one screen in which i faced one issue of extra space see in pic.
Issue link (https://www.dropbox.com/s/ttlpnuu0ikaf515/Screen%20Shot%202018-02-05%20at%205.47.54%20PM.png?dl=0)
回答1:
I don't want to change implementation , but if you used this you won't see any white space
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow(_:)), name:NSNotification.Name.UIKeyboardWillShow, object: self.view.window)
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide(_:)), name:NSNotification.Name.UIKeyboardWillHide, object: self.view.window)
//
@objc func handleKeyboardDidShow (notification: NSNotification)
{
let keyboardRectAsObject = notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue
var keyboardRect = CGRect.zero
keyboardRectAsObject.getValue(&keyboardRect)
self.containerViewBotcon.constant = -1 * keyboardRect.height
UIView.animate(withDuration: 0.5,animations: {
self.view.layoutIfNeeded()
})
}
@objc func handleKeyboardWillHide(notification: NSNotification)
{
self.containerViewBotcon.constant = 0
UIView.animate(withDuration: 0.5,animations: {
self.view.layoutIfNeeded()
})
}
回答2:
if #available(iOS 11.0, *) {
self.webView.scrollView.contentInsetAdjustmentBehavior = .never
} else {
self.automaticallyAdjustsScrollViewInsets = false
}
And UIScrollViewDelegate
func scrollViewDidChangeAdjustedContentInset(_ scrollView: UIScrollView) {
Logger.print("scrollViewDidChangeAdjustedContentInset")
if #available(iOS 12.0, *) {
for view in webView.subviews {
if let scrollView = view as? UIScrollView {
scrollView.setContentOffset(.zero, animated: true)
}
}
}
}
Worked
来源:https://stackoverflow.com/questions/48622688/extra-space-issue-at-keyboard-hide-show