Swift 3 / WKWebView - 如何在单击表单输入时获取有效约束?

时间:2017-11-08 02:38:27

标签: ios swift wkwebview

我有以下代码:

override func loadView() {
    super.loadView()
    let webConfiguration = WKWebViewConfiguration()
    webView = WKWebView(frame: .zero, configuration: webConfiguration)
    webView.navigationDelegate = self
    view = webView
}

override func viewDidLoad() {
    super.viewDidLoad()
    let myURL = URL(string: "https://www.w3schools.com/html/html_forms.asp")
    let myRequest = URLRequest(url: myURL!)
    webView.load(myRequest)
}

但是当我运行它时,只要我单击表单中的输入来键入内容,键盘就会出现,从而推动整个视图。控制台显示以下内容:

[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:0x1c42894c0 h=-&- v=-&- UIToolbar:0x125d24040.width == _UIInputViewContent:0x125d232c0.width   (active)>",
    "<NSAutoresizingMaskLayoutConstraint:0x1c4289600 h=--& v=--& _UIInputViewContent:0x125d232c0.width == 0   (active)>",
    "<NSLayoutConstraint:0x1c4281360 H:|-(0)-[_UIButtonBarStackView:0x125e10970]   (active, names: '|':_UIToolbarContentView:0x125d24480 )>",
    "<NSLayoutConstraint:0x1c42813b0 _UIButtonBarStackView:0x125e10970.trailing == _UIToolbarContentView:0x125d24480.trailing + 8   (active)>",
    "<NSLayoutConstraint:0x1c0282df0 _UIToolbarContentView:0x125d24480.trailing == UIToolbar:0x125d24040.trailing   (active)>",
    "<NSLayoutConstraint:0x1c0282e90 H:|-(0)-[_UIToolbarContentView:0x125d24480]   (active, names: '|':UIToolbar:0x125d24040 )>",
    "<NSLayoutConstraint:0x1c4288980 H:|-(>=5)-[_UIModernBarButton:0x125e33a00]   (active, names: '|':_UIButtonBarButton:0x125e333b0 )>",
    "<NSLayoutConstraint:0x1c42889d0 H:[_UIModernBarButton:0x125e33a00]-(>=5)-|   (active, names: '|':_UIButtonBarButton:0x125e333b0 )>",
    "<NSLayoutConstraint:0x1c028d5c0 H:|-(8)-[_UIModernBarButton:0x125d4fa20'Done']   (active, names: '|':_UIButtonBarButton:0x125e34320 )>",
    "<NSLayoutConstraint:0x1c028d610 H:[_UIModernBarButton:0x125d4fa20'Done']-(0)-|   (active, names: '|':_UIButtonBarButton:0x125e34320 )>",
    "<NSLayoutConstraint:0x1c028d9d0 'UISV-canvas-connection' UILayoutGuide:0x1c41b88e0'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x125e31e70.leading   (active)>",
    "<NSLayoutConstraint:0x1c028db10 'UISV-canvas-connection' UILayoutGuide:0x1c41b88e0'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x125e34320.trailing   (active)>",
    "<NSLayoutConstraint:0x1c028db60 'UISV-spacing' H:[_UIButtonBarButton:0x125e31e70]-(0)-[UIView:0x125e331d0]   (active)>",
    "<NSLayoutConstraint:0x1c028dbb0 'UISV-spacing' H:[UIView:0x125e331d0]-(0)-[_UIButtonBarButton:0x125e333b0]   (active)>",
    "<NSLayoutConstraint:0x1c028dc00 'UISV-spacing' H:[_UIButtonBarButton:0x125e333b0]-(0)-[UIView:0x125e34140]   (active)>",
    "<NSLayoutConstraint:0x1c028dc50 'UISV-spacing' H:[UIView:0x125e34140]-(0)-[_UIButtonBarButton:0x125e34320]   (active)>",
    "<NSLayoutConstraint:0x1c409e1e0 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x1c41b88e0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIButtonBarStackView:0x125e10970 )>",
    "<NSLayoutConstraint:0x1c4281130 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x1c41b88e0'UIViewLayoutMarginsGuide']-(0)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x125e10970 )>"
)

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

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-11-07 21:28:10.485532-0500 test[1049:199135] [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:0x1c42894c0 h=-&- v=-&- UIToolbar:0x125d24040.width == _UIInputViewContent:0x125d232c0.width   (active)>",
    "<NSAutoresizingMaskLayoutConstraint:0x1c4289600 h=--& v=--& _UIInputViewContent:0x125d232c0.width == 0   (active)>",
    "<NSLayoutConstraint:0x1c4281360 H:|-(0)-[_UIButtonBarStackView:0x125e10970]   (active, names: '|':_UIToolbarContentView:0x125d24480 )>",
    "<NSLayoutConstraint:0x1c42813b0 _UIButtonBarStackView:0x125e10970.trailing == _UIToolbarContentView:0x125d24480.trailing + 8   (active)>",
    "<NSLayoutConstraint:0x1c0282df0 _UIToolbarContentView:0x125d24480.trailing == UIToolbar:0x125d24040.trailing   (active)>",
    "<NSLayoutConstraint:0x1c0282e90 H:|-(0)-[_UIToolbarContentView:0x125d24480]   (active, names: '|':UIToolbar:0x125d24040 )>",
    "<NSLayoutConstraint:0x1c4288340 H:|-(0)-[_UIModernBarButton:0x125e320c0]   (active, names: '|':_UIButtonBarButton:0x125e31e70 )>",
    "<NSLayoutConstraint:0x1c4288390 H:[_UIModernBarButton:0x125e320c0]-(>=8)-|   (active, names: '|':_UIButtonBarButton:0x125e31e70 )>",
    "<NSLayoutConstraint:0x1c028d5c0 H:|-(8)-[_UIModernBarButton:0x125d4fa20'Done']   (active, names: '|':_UIButtonBarButton:0x125e34320 )>",
    "<NSLayoutConstraint:0x1c028d610 H:[_UIModernBarButton:0x125d4fa20'Done']-(0)-|   (active, names: '|':_UIButtonBarButton:0x125e34320 )>",
    "<NSLayoutConstraint:0x1c028d9d0 'UISV-canvas-connection' UILayoutGuide:0x1c41b88e0'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x125e31e70.leading   (active)>",
    "<NSLayoutConstraint:0x1c028db10 'UISV-canvas-connection' UILayoutGuide:0x1c41b88e0'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x125e34320.trailing   (active)>",
    "<NSLayoutConstraint:0x1c028db60 'UISV-spacing' H:[_UIButtonBarButton:0x125e31e70]-(0)-[UIView:0x125e331d0]   (active)>",
    "<NSLayoutConstraint:0x1c028dbb0 'UISV-spacing' H:[UIView:0x125e331d0]-(0)-[_UIButtonBarButton:0x125e333b0]   (active)>",
    "<NSLayoutConstraint:0x1c028dc00 'UISV-spacing' H:[_UIButtonBarButton:0x125e333b0]-(0)-[UIView:0x125e34140]   (active)>",
    "<NSLayoutConstraint:0x1c028dc50 'UISV-spacing' H:[UIView:0x125e34140]-(0)-[_UIButtonBarButton:0x125e34320]   (active)>",
    "<NSLayoutConstraint:0x1c409e1e0 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x1c41b88e0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIButtonBarStackView:0x125e10970 )>",
    "<NSLayoutConstraint:0x1c4281130 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x1c41b88e0'UIViewLayoutMarginsGuide']-(0)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x125e10970 )>"
)

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

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

如何在单击表单中的输入时使WKWebView具有有效约束?

0 个答案:

没有答案