键盘隐藏显示的额外空间问题

时间:2018-02-05 12:32:03

标签: ios objective-c iphone iqkeyboardmanager

希望你做得好!

我在项目中有一个使用过的IQKeyboardManager库,我有一个屏幕,其中我遇到了一个额外空间问题,请参阅图片。

问题链接(https://www.dropbox.com/s/ttlpnuu0ikaf515/Screen%20Shot%202018-02-05%20at%205.47.54%20PM.png?dl=0

2 个答案:

答案 0 :(得分:0)

我不想更改实现,但是如果你使用它,你将看不到任何空格

 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()

    })

}

答案 1 :(得分: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)
             }
         }
    }
}

工作