【问题标题】:Extra space issue at Keyboard hide show键盘隐藏秀的额外空间问题
【发布时间】:2018-07-15 07:35:17
【问题描述】:
【问题讨论】:
标签:
ios
objective-c
iphone
iqkeyboardmanager
【解决方案1】:
我不想更改实现,但如果你使用它,你将看不到任何空白
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
}
还有 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)
}
}
}
}
工作