希望你一切顺利!
我在一个项目中有一个使用过的 IQKeyboardManager 库,并且我在一个屏幕中遇到了一个额外空间问题,如图所示。
问题链接(https://www.dropbox.com/s/ttlpnuu0ikaf515/Screen%20Shot%202018-02-05%20at%205.47.54%20PM.png?dl=0)
希望你一切顺利!
我在一个项目中有一个使用过的 IQKeyboardManager 库,并且我在一个屏幕中遇到了一个额外空间问题,如图所示。
问题链接(https://www.dropbox.com/s/ttlpnuu0ikaf515/Screen%20Shot%202018-02-05%20at%205.47.54%20PM.png?dl=0)
if #available(iOS 11.0, *) {
self.webView.scrollView.contentInsetAdjustmentBehavior = .never
} else {
self.automaticallyAdjustsScrollViewInsets = false
}
和 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)
}
}
}
}
工作过
我不想更改实现,但是如果您使用它,您将看不到任何空白
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()
})
}