WKWebView constrains issue when keyboard pops up

后端 未结 3 1936
终归单人心
终归单人心 2020-12-30 02:34

When an input in WKWebView gets focused a constraints error pops up.

Code:

class ViewController: UIViewController {
          


        
相关标签:
3条回答
  • 2020-12-30 03:15

    My assumption is this a bug in ios 11. The complaints are about the components in the button bar for the keyboard which are all using default values set by the os. I have run the same code on both ios 9 and ios 10 and get no error messages.

    0 讨论(0)
  • 2020-12-30 03:24

    Having the same issue. I'm running a clean project, vanilla setup and this issue comes up as soon as the webview keyboard gets focus. It seems to be a common issue, might just be a bug in iOS 11.

    Also see:

    WKWebView LayoutConstraints issue

    0 讨论(0)
  • 2020-12-30 03:29

    One or more constraints are not compatible at the same time when keyboard is open.

    Instead of doing frame by hand, try setting constraints to ur WKWebView.

    private func addWKWebView(){
        let wv = WKWebView()
        view.addSubview(wv);
        wv.translatesAutoresizingMaskIntoConstraints = false
    
    
        wv.widthAnchor.constraint(equalTo:   view.widthAnchor  ).isActive = true
        wv.heightAnchor.constraint(equalTo:  view.heightAnchor ).isActive = true
        wv.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        wv.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    }
    

    or Something like this:

    private func addWKWebView(){
        let wv = WKWebView()
        view.addSubview(wv);
        wv.translatesAutoresizingMaskIntoConstraints = false
    
    
        wv.widthAnchor.constraint(equalToConstant:  100).isActive = true
        wv.heightAnchor.constraint(equalToConstant: 100).isActive = true
        wv.widthAnchor.constraint(equalToConstant:  100).isActive = true
        wv.heightAnchor.constraint(equalToConstant: 100).isActive = true
    }
    

    U need to play around with your constraints to set the WkWebView where u want.

    0 讨论(0)
提交回复
热议问题