当键盘弹出时,WKWebView会限制问题
当WKWebView
的输入WKWebView
会弹出约束错误。
码:
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad(); let wv = WKWebView(frame: CGRect(x: 100, y: 100, width: 100, height: 100)); wv.loadHTMLString("", baseURL: nil); // it also can be select, it makes no difference view.addSubview(wv); } }
错误日志:
2017-11-05 00:26:28.861439+0700 achievator[20048:75393577] [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) ( "", "", "", "", "", "", "", "=8)-| (active, names: '|':_UIButtonBarButton:0x7f854050e7f0 )>", "", "", "", "", "", "", "", "", "", "" ) Will attempt to recover by breaking constraint =8)-| (active, names: '|':_UIButtonBarButton:0x7f854050e7f0 )> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. 2017-11-05 00:26:28.863156+0700 achievator[20048:75393577] [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) ( "", "", "", "", "", "", "=5)-[_UIModernBarButton:0x7f8540510b40] (active, names: '|':_UIButtonBarButton:0x7f854050ea30 )>", "=5)-| (active, names: '|':_UIButtonBarButton:0x7f854050ea30 )>", "", "", "", "", "", "", "", "", "", "" ) Will attempt to recover by breaking constraint =5)-| (active, names: '|':_UIButtonBarButton:0x7f854050ea30 )> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
我的假设是ios 11中的一个错误。投诉是关于键盘按钮栏中的组件,它们都使用了os设置的默认值。 我在ios 9和ios 10上都运行了相同的代码,并且没有收到任何错误消息。
键盘打开时,一个或多个约束不兼容。
尝试将约束设置为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 }
或者像这样的东西:
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 }
你需要使用你的约束来设置你想要的WkWebView。
有同样的问题。 我正在运行一个干净的项目,vanilla设置,一旦webview键盘获得焦点,就会出现此问题。 这似乎是一个常见问题,可能只是iOS 11中的一个错误。
另见:
WKWebView LayoutConstraints问题