WKWebView проблемы с ограничениями при отображении клавиатуры - PullRequest
0 голосов
/ 11 февраля 2019

Клавиатура не работает при запросе при фокусировке на поле ввода из WKWebView, и мне интересно, как установить ограничения, чтобы избежать этой проблемы

Страница загружается просто отлично.На странице есть поле ввода.Когда я нажимаю на поле ввода, клавиатура выскакивает, но фокус на поле больше не устанавливается и ничего не может быть введено.xcode выдает следующий журнал ошибок:

override func viewDidLoad() {
  super.viewDidLoad()
  setupWebView()
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
  self.showWebView()
}

func showWebView() {
        webView.frame = view.frame
        webView.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(webView)

view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[webView]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["webView":webView]))
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-20-[webView]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["webView":webView]))

    }

    func setupWebView() {
        let webConfiguration = WKWebViewConfiguration()

        webView = WKWebView(frame:.zero, configuration: webConfiguration)
        webView.uiDelegate = self
        webView?.navigationDelegate = self

        //Disable scroll of WebView
        webView.scrollView.bounces = false

        webView.translatesAutoresizingMaskIntoConstraints = false

        let url = URL(string: self.url)
        let request = URLRequest(url: url!)
        print(request)
        webView.load(request)
    }

Журнал ошибок:

2019-02-11 15:53:46.940718+0100 AppName[9824:4549339] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles

2019-02-11 15:53:46.943297+0100 AppName[9824:4549339] [MC] Reading from public effective user settings.

2019-02-11 15:53:47.085142+0100 AppName[9824:4549339] API error: <_UIKBCompatInputView: 0x113d03880; frame = (0 0; 0 0); layer = <CALayer: 0x28017c800>> returned 0 width, assuming UIViewNoIntrinsicMetric

2019-02-11 15:53:47.085268+0100 AppName[9824:4549339] API error: <_UIKBCompatInputView: 0x113d03880; frame = (0 0; 0 0); layer = <CALayer: 0x28017c800>> returned 0 width, assuming UIViewNoIntrinsicMetric
2019-02-11 15:53:47.123997+0100 AppName[9824:4549339] [LayoutConstraints] Unable to simultaneously satisfy constraints.
  Probably at least one of the constraints in the following list is one you don't want. 
  Try this: 
    (1) look at each constraint and try to figure out which you don't expect; 
    (2) find the code that added the unwanted constraint or constraints and fix it. 
  (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x282275ae0 h=-&- v=-&- _UIToolbarContentView:0x113d3d9e0.width == UIToolbar:0x113d3d5a0.width   (active)>",
    "<NSLayoutConstraint:0x282262bc0 H:|-(0)-[_UIButtonBarStackView:0x113d3f970]   (active, names: '|':_UIToolbarContentView:0x113d3d9e0 )>",
    "<NSLayoutConstraint:0x2822637a0 _UIButtonBarStackView:0x113d3f970.trailing == _UIToolbarContentView:0x113d3d9e0.trailing   (active)>",
    "<NSLayoutConstraint:0x282273cf0 H:|-(16)-[_UIModernBarButton:0x113d54b00]   (active, names: '|':_UIButtonBarButton:0x113d546b0 )>",
    "<NSLayoutConstraint:0x282273d40 H:[_UIModernBarButton:0x113d54b00]-(>=8)-|   (active, names: '|':_UIButtonBarButton:0x113d546b0 )>",
    "<NSLayoutConstraint:0x282278320 H:|-(>=5)-[_UIModernBarButton:0x113d56e30]   (active, names: '|':_UIButtonBarButton:0x113d567e0 )>",
    "<NSLayoutConstraint:0x282278370 H:[_UIModernBarButton:0x113d56e30]-(>=5)-|   (active, names: '|':_UIButtonBarButton:0x113d567e0 )>",
    "<NSLayoutConstraint:0x282278dc0 H:|-(8)-[_UIModernBarButton:0x113d57ee0'Done']   (active, names: '|':_UIButtonBarButton:0x113d57350 )>",
    "<NSLayoutConstraint:0x282278e10 H:[_UIModernBarButton:0x113d57ee0'Done']-(16)-|   (active, names: '|':_UIButtonBarButton:0x113d57350 )>",
    "<NSLayoutConstraint:0x282275090 'UISV-canvas-connection' UILayoutGuide:0x2838457a0'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x113d546b0.leading   (active)>",
    "<NSLayoutConstraint:0x2822750e0 'UISV-canvas-connection' UILayoutGuide:0x2838457a0'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x113d57350.trailing   (active)>",
    "<NSLayoutConstraint:0x282275130 'UISV-spacing' H:[_UIButtonBarButton:0x113d546b0]-(0)-[UIView:0x113d56600]   (active)>",
    "<NSLayoutConstraint:0x282275180 'UISV-spacing' H:[UIView:0x113d56600]-(0)-[_UIButtonBarButton:0x113d567e0]   (active)>",
    "<NSLayoutConstraint:0x2822751d0 'UISV-spacing' H:[_UIButtonBarButton:0x113d567e0]-(0)-[UIView:0x113d57170]   (active)>",
    "<NSLayoutConstraint:0x282275220 'UISV-spacing' H:[UIView:0x113d57170]-(0)-[_UIButtonBarButton:0x113d57350]   (active)>",
    "<NSLayoutConstraint:0x282275c70 'UIView-Encapsulated-Layout-Width' UIToolbar:0x113d3d5a0.width == 0   (active)>",
    "<NSLayoutConstraint:0x2822699f0 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x2838457a0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIButtonBarStackView:0x113d3f970 )>",
    "<NSLayoutConstraint:0x282269a90 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x2838457a0'UIViewLayoutMarginsGuide']-(0)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x113d3f970 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x282273d40 H:[_UIModernBarButton:0x113d54b00]-(>=8)-|   (active, names: '|':_UIButtonBarButton:0x113d546b0 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.



2019-02-11 15:53:47.134917+0100 AppName[9824:4549339] [LayoutConstraints] Unable to simultaneously satisfy constraints.
  Probably at least one of the constraints in the following list is one you don't want. 
  Try this: 
    (1) look at each constraint and try to figure out which you don't expect; 
    (2) find the code that added the unwanted constraint or constraints and fix it. 
  (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x282275ae0 h=-&- v=-&- _UIToolbarContentView:0x113d3d9e0.width == UIToolbar:0x113d3d5a0.width   (active)>",
    "<NSLayoutConstraint:0x282262bc0 H:|-(0)-[_UIButtonBarStackView:0x113d3f970]   (active, names: '|':_UIToolbarContentView:0x113d3d9e0 )>",
    "<NSLayoutConstraint:0x2822637a0 _UIButtonBarStackView:0x113d3f970.trailing == _UIToolbarContentView:0x113d3d9e0.trailing   (active)>",
    "<NSLayoutConstraint:0x282278320 H:|-(>=5)-[_UIModernBarButton:0x113d56e30]   (active, names: '|':_UIButtonBarButton:0x113d567e0 )>",
    "<NSLayoutConstraint:0x282278370 H:[_UIModernBarButton:0x113d56e30]-(>=5)-|   (active, names: '|':_UIButtonBarButton:0x113d567e0 )>",
    "<NSLayoutConstraint:0x282278dc0 H:|-(8)-[_UIModernBarButton:0x113d57ee0'Done']   (active, names: '|':_UIButtonBarButton:0x113d57350 )>",
    "<NSLayoutConstraint:0x282278e10 H:[_UIModernBarButton:0x113d57ee0'Done']-(16)-|   (active, names: '|':_UIButtonBarButton:0x113d57350 )>",
    "<NSLayoutConstraint:0x282275090 'UISV-canvas-connection' UILayoutGuide:0x2838457a0'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x113d546b0.leading   (active)>",
    "<NSLayoutConstraint:0x2822750e0 'UISV-canvas-connection' UILayoutGuide:0x2838457a0'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x113d57350.trailing   (active)>",
    "<NSLayoutConstraint:0x282275130 'UISV-spacing' H:[_UIButtonBarButton:0x113d546b0]-(0)-[UIView:0x113d56600]   (active)>",
    "<NSLayoutConstraint:0x282275180 'UISV-spacing' H:[UIView:0x113d56600]-(0)-[_UIButtonBarButton:0x113d567e0]   (active)>",
    "<NSLayoutConstraint:0x2822751d0 'UISV-spacing' H:[_UIButtonBarButton:0x113d567e0]-(0)-[UIView:0x113d57170]   (active)>",
    "<NSLayoutConstraint:0x282275220 'UISV-spacing' H:[UIView:0x113d57170]-(0)-[_UIButtonBarButton:0x113d57350]   (active)>",
    "<NSLayoutConstraint:0x282275c70 'UIView-Encapsulated-Layout-Width' UIToolbar:0x113d3d5a0.width == 0   (active)>",
    "<NSLayoutConstraint:0x2822699f0 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x2838457a0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIButtonBarStackView:0x113d3f970 )>",
    "<NSLayoutConstraint:0x282269a90 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x2838457a0'UIViewLayoutMarginsGuide']-(0)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x113d3f970 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x282278370 H:[_UIModernBarButton:0x113d56e30]-(>=5)-|   (active, names: '|':_UIButtonBarButton:0x113d567e0 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

Я потратил часы на это сейчас без какого-либо успешного результата.Я прочитал несколько похожих тем без какого-либо хорошего ответа.Мое приложение работало просто отлично, но вдруг эта проблема возникла из ниоткуда.Был бы рад за некоторое руководство

1 Ответ

0 голосов
/ 11 февраля 2019

Было бы трудно сказать, что не так с вашими ограничениями, не глядя на раскадровку.Иногда полезно, если вы очистите все ограничения и добавите их снова, думая о том, какой элемент должен придерживаться какого.Изменение «Вид как ...» для просмотра вида на экранах разных размеров в раскадровке помогает визуализировать, где вы ошиблись.

...