【问题标题】:Extra space issue at Keyboard hide show键盘隐藏秀的额外空间问题
【发布时间】:2018-07-15 07:35:17
【问题描述】:

希望你一切顺利!

我在一个项目中有一个使用过的 IQKeyboardManager 库,我在一个屏幕中遇到了一个额外空间问题,如图所示。

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

【问题讨论】:

    标签: 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)
                   }
               }
          }
      }
      

      工作

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-07-15
        • 1970-01-01
        • 1970-01-01
        • 2022-06-12
        • 2020-10-14
        • 1970-01-01
        • 2014-11-14
        • 2011-06-07
        相关资源
        最近更新 更多