使用WKWebView
构建应用,在HTML中我有一个输入文本字段,当我专注于文本字段键盘弹出并收到LayoutConstraints
错误时,
无法弄清楚如何解决我的问题。
我的简单实现:
class WebViewBase: UIViewController, WKUIDelegate, WKNavigationDelegate {
lazy var webView: WKWebView = {
let webConfiguration = WKWebViewConfiguration()
let web = WKWebView(frame: .zero, configuration: webConfiguration)
web.uiDelegate = self
web.navigationDelegate = self
return web
}()
lazy var webViewCont:UIView = {
let view = UIView()
return view
}()
lazy var navBarHeight:CGFloat = {
guard let navbar = self.navigationController else {
return 64
}
return navbar.navigationBar.frame.size.height
}()
let screenSize:CGRect = {
return UIScreen.main.bounds
}()
override func loadView() {
super.loadView()
webViewCont = webView
webViewCont.frame = CGRect(x: 0, y: 0, width: screenSize.width, height: screenSize.height - navBarHeight - UIApplication.shared.statusBarFrame.height)
self.view.addSubview(webViewCont)
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.barTintColor = UIColor.rgb(red:255, green:255, blue:255)
//UINavigationBar.appearance().barTintColor = UIColor.rgb(red:230, green:32, blue:31)
if let navigationController = self.navigationController {
navigationController.navigationBar.setBackgroundImage(UIImage(), for: .default)
}
self.navigationController?.setNavigationBarHidden(false, animated: true)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyBoardChangeNotification(_:)), name: NSNotification.Name.UIKeyboardWillChangeFrame, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyBoardHideNotification(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
callLink()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NotificationCenter.default.removeObserver(self)
}
func callLink() {
//Globals.activitiIndicator.showLoading()
let urlStr:String = "https://google.com"
let url:NSURL = NSURL(string: urlStr)!
let request:NSMutableURLRequest = NSMutableURLRequest(url: url as URL)
webView.load(request as URLRequest)
}
@objc func handleKeyBoardChangeNotification(_ notification: NSNotification) {
if let info = notification.userInfo {
guard let keyboardSize = (info[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size else {
return
}
self.webViewCont.frame.size.height = screenSize.height - keyboardSize.height - navBarHeight - UIApplication.shared.statusBarFrame.height
}
}
@objc func handleKeyBoardHideNotification(_ notification: NSNotification) {
if let info = notification.userInfo {
guard let keyboardSize = (info[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size else {
return
}
self.webViewCont.frame.size.height += keyboardSize.height
}
}
}
并收到错误:
2018-02-01 19:01:24.076820+0400 IriSee[1772:742866] API error: <_UIKBCompatInputView: 0x104fd3890; frame = (0 0; 0 0); layer = <CALayer: 0x104fd3190>> returned 0 width, assuming UIViewNoIntrinsicMetric 2018-02-01 19:01:24.077076+0400 IriSee[1772:742866] API error: <_UIKBCompatInputView: 0x104fd3890; frame = (0 0; 0 0); layer = <CALayer: 0x104fd3190>> returned 0 width, assuming UIViewNoIntrinsicMetric 2018-02-01 19:01:24.173133+0400 IriSee[1772:742866] [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:0x10851d0f0 h=-&- v=-&- _UIToolbarContentView:0x104fbc760.width == UIToolbar:0x104fbbc90.width (active)>", "<NSLayoutConstraint:0x104fc21b0 H:|-(8)-[_UIButtonBarStackView:0x104fc0500] (active, names: '|':_UIToolbarContentView:0x104fbc760 )>", "<NSLayoutConstraint:0x104fc2300 _UIButtonBarStackView:0x104fc0500.trailing == _UIToolbarContentView:0x104fbc760.trailing (active)>", "<NSLayoutConstraint:0x10676a070 H:|-(8)-[_UIModernBarButton:0x1067695b0] (active, names: '|':_UIButtonBarButton:0x106768c10 )>", "<NSLayoutConstraint:0x10676a1c0 H:[_UIModernBarButton:0x1067695b0]-(>=8)-| (active, names: '|':_UIButtonBarButton:0x106768c10 )>", "<NSLayoutConstraint:0x10850c2d0 H:|-(>=5)-[_UIModernBarButton:0x10850b800] (active, names: '|':_UIButtonBarButton:0x10850b440 )>", "<NSLayoutConstraint:0x10850c420 H:[_UIModernBarButton:0x10850b800]-(>=5)-| (active, names: '|':_UIButtonBarButton:0x10850b440 )>", "<NSLayoutConstraint:0x10676b990 H:|-(8)-[_UIModernBarButton:0x10850f680'Done'] (active, names: '|':_UIButtonBarButton:0x10850d180 )>", "<NSLayoutConstraint:0x10676bae0 H:[_UIModernBarButton:0x10850f680'Done']-(8)-| (active, names: '|':_UIButtonBarButton:0x10850d180 )>", "<NSLayoutConstraint:0x108509a00 'UISV-canvas-connection' UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x106768c10.leading (active)>", "<NSLayoutConstraint:0x108518110 'UISV-canvas-connection' UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x10850d180.trailing (active)>", "<NSLayoutConstraint:0x108518a30 'UISV-spacing' H:[_UIButtonBarButton:0x106768c10]-(0)-[UIView:0x10850b0e0] (active)>", "<NSLayoutConstraint:0x108518420 'UISV-spacing' H:[UIView:0x10850b0e0]-(0)-[_UIButtonBarButton:0x10850b440] (active)>", "<NSLayoutConstraint:0x1085193a0 'UISV-spacing' H:[_UIButtonBarButton:0x10850b440]-(0)-[UIView:0x10850ce20] (active)>", "<NSLayoutConstraint:0x108519740 'UISV-spacing' H:[UIView:0x10850ce20]-(0)-[_UIButtonBarButton:0x10850d180] (active)>", "<NSLayoutConstraint:0x108520840 'UIView-Encapsulated-Layout-Width' UIToolbar:0x104fbbc90.width == 0 (active)>", "<NSLayoutConstraint:0x104fc1930 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIButtonBarStackView:0x104fc0500 )>", "<NSLayoutConstraint:0x104fc1b50 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide']-(0)-|(LTR) (active, names: '|':_UIButtonBarStackView:0x104fc0500 )>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x10676a1c0 H:[_UIModernBarButton:0x1067695b0]-(>=8)-| (active, names: '|':_UIButtonBarButton:0x106768c10 )> 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. 2018-02-01 19:01:24.210139+0400 IriSee[1772:742866] [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:0x10851d0f0 h=-&- v=-&- _UIToolbarContentView:0x104fbc760.width == UIToolbar:0x104fbbc90.width (active)>", "<NSLayoutConstraint:0x104fc21b0 H:|-(8)-[_UIButtonBarStackView:0x104fc0500] (active, names: '|':_UIToolbarContentView:0x104fbc760 )>", "<NSLayoutConstraint:0x104fc2300 _UIButtonBarStackView:0x104fc0500.trailing == _UIToolbarContentView:0x104fbc760.trailing (active)>", "<NSLayoutConstraint:0x10850c2d0 H:|-(>=5)-[_UIModernBarButton:0x10850b800] (active, names: '|':_UIButtonBarButton:0x10850b440 )>", "<NSLayoutConstraint:0x10850c420 H:[_UIModernBarButton:0x10850b800]-(>=5)-| (active, names: '|':_UIButtonBarButton:0x10850b440 )>", "<NSLayoutConstraint:0x10676b990 H:|-(8)-[_UIModernBarButton:0x10850f680'Done'] (active, names: '|':_UIButtonBarButton:0x10850d180 )>", "<NSLayoutConstraint:0x10676bae0 H:[_UIModernBarButton:0x10850f680'Done']-(8)-| (active, names: '|':_UIButtonBarButton:0x10850d180 )>", "<NSLayoutConstraint:0x108509a00 'UISV-canvas-connection' UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x106768c10.leading (active)>", "<NSLayoutConstraint:0x108518110 'UISV-canvas-connection' UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x10850d180.trailing (active)>", "<NSLayoutConstraint:0x108518a30 'UISV-spacing' H:[_UIButtonBarButton:0x106768c10]-(0)-[UIView:0x10850b0e0] (active)>", "<NSLayoutConstraint:0x108518420 'UISV-spacing' H:[UIView:0x10850b0e0]-(0)-[_UIButtonBarButton:0x10850b440] (active)>", "<NSLayoutConstraint:0x1085193a0 'UISV-spacing' H:[_UIButtonBarButton:0x10850b440]-(0)-[UIView:0x10850ce20] (active)>", "<NSLayoutConstraint:0x108519740 'UISV-spacing' H:[UIView:0x10850ce20]-(0)-[_UIButtonBarButton:0x10850d180] (active)>", "<NSLayoutConstraint:0x108520840 'UIView-Encapsulated-Layout-Width' UIToolbar:0x104fbbc90.width == 0 (active)>", "<NSLayoutConstraint:0x104fc1930 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIButtonBarStackView:0x104fc0500 )>", "<NSLayoutConstraint:0x104fc1b50 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide']-(0)-|(LTR) (active, names: '|':_UIButtonBarStackView:0x104fc0500 )>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x10850c420 H:[_UIModernBarButton:0x10850b800]-(>=5)-| (active, names: '|':_UIButtonBarButton:0x10850b440 )> 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. 2018-02-01 19:01:24.214990+0400 IriSee[1772:742866] [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:0x10851d0f0 h=-&- v=-&- _UIToolbarContentView:0x104fbc760.width == UIToolbar:0x104fbbc90.width (active)>", "<NSLayoutConstraint:0x104fc21b0 H:|-(8)-[_UIButtonBarStackView:0x104fc0500] (active, names: '|':_UIToolbarContentView:0x104fbc760 )>", "<NSLayoutConstraint:0x104fc2300 _UIButtonBarStackView:0x104fc0500.trailing == _UIToolbarContentView:0x104fbc760.trailing (active)>", "<NSLayoutConstraint:0x10676b990 H:|-(8)-[_UIModernBarButton:0x10850f680'Done'] (active, names: '|':_UIButtonBarButton:0x10850d180 )>", "<NSLayoutConstraint:0x10676bae0 H:[_UIModernBarButton:0x10850f680'Done']-(8)-| (active, names: '|':_UIButtonBarButton:0x10850d180 )>", "<NSLayoutConstraint:0x108509a00 'UISV-canvas-connection' UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x106768c10.leading (active)>", "<NSLayoutConstraint:0x108518110 'UISV-canvas-connection' UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x10850d180.trailing (active)>", "<NSLayoutConstraint:0x108518a30 'UISV-spacing' H:[_UIButtonBarButton:0x106768c10]-(0)-[UIView:0x10850b0e0] (active)>", "<NSLayoutConstraint:0x108518420 'UISV-spacing' H:[UIView:0x10850b0e0]-(0)-[_UIButtonBarButton:0x10850b440] (active)>", "<NSLayoutConstraint:0x1085193a0 'UISV-spacing' H:[_UIButtonBarButton:0x10850b440]-(0)-[UIView:0x10850ce20] (active)>", "<NSLayoutConstraint:0x108519740 'UISV-spacing' H:[UIView:0x10850ce20]-(0)-[_UIButtonBarButton:0x10850d180] (active)>", "<NSLayoutConstraint:0x108520840 'UIView-Encapsulated-Layout-Width' UIToolbar:0x104fbbc90.width == 0 (active)>", "<NSLayoutConstraint:0x104fc1930 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIButtonBarStackView:0x104fc0500 )>", "<NSLayoutConstraint:0x104fc1b50 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide']-(0)-|(LTR) (active, names: '|':_UIButtonBarStackView:0x104fc0500 )>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x10676bae0 H:[_UIModernBarButton:0x10850f680'Done']-(8)-| (active, names: '|':_UIButtonBarButton:0x10850d180 )> 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. 2018-02-01 19:01:24.219711+0400 IriSee[1772:742866] [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:0x10851d0f0 h=-&- v=-&- _UIToolbarContentView:0x104fbc760.width == UIToolbar:0x104fbbc90.width (active)>", "<NSLayoutConstraint:0x104fc21b0 H:|-(8)-[_UIButtonBarStackView:0x104fc0500] (active, names: '|':_UIToolbarContentView:0x104fbc760 )>", "<NSLayoutConstraint:0x104fc2300 _UIButtonBarStackView:0x104fc0500.trailing == _UIToolbarContentView:0x104fbc760.trailing (active)>", "<NSLayoutConstraint:0x108509a00 'UISV-canvas-connection' UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x106768c10.leading (active)>", "<NSLayoutConstraint:0x108518110 'UISV-canvas-connection' UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x10850d180.trailing (active)>", "<NSLayoutConstraint:0x108518a30 'UISV-spacing' H:[_UIButtonBarButton:0x106768c10]-(0)-[UIView:0x10850b0e0] (active)>", "<NSLayoutConstraint:0x108518420 'UISV-spacing' H:[UIView:0x10850b0e0]-(0)-[_UIButtonBarButton:0x10850b440] (active)>", "<NSLayoutConstraint:0x1085193a0 'UISV-spacing' H:[_UIButtonBarButton:0x10850b440]-(0)-[UIView:0x10850ce20] (active)>", "<NSLayoutConstraint:0x108519740 'UISV-spacing' H:[UIView:0x10850ce20]-(0)-[_UIButtonBarButton:0x10850d180] (active)>", "<NSLayoutConstraint:0x108520840 'UIView-Encapsulated-Layout-Width' UIToolbar:0x104fbbc90.width == 0 (active)>", "<NSLayoutConstraint:0x104fc1930 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIButtonBarStackView:0x104fc0500 )>", "<NSLayoutConstraint:0x104fc1b50 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x104fc1740'UIViewLayoutMarginsGuide']-(0)-|(LTR) (active, names: '|':_UIButtonBarStackView:0x104fc0500 )>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x108519740 'UISV-spacing' H:[UIView:0x10850ce20]-(0)-[_UIButtonBarButton:0x10850d180] (active)> 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. 2018-02-01 19:01:24.222119+0400 IriSee[1772:742866] [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:0x10851d0f0 h=-&- v=-&- _UIToolbarContentView:0x104fbc760.width == UIToolbar:0x104fbbc90.width (active)>", "<NSLayoutConstraint:0x104fc21b0 H:|-(8)-[_UIButtonBarStackView:0x104fc0500] (active, names: '|':_UIToolbarContentView:0x104fbc760 )>", "<NSLayoutConstraint:0x104fc2300 _UIButtonBarStackView:0x104fc0500.trailing == _UIToolbarContentView:0x104fbc760.trailing (active)>", "<NSLayoutConstraint:0x108520840 'UIView-Encapsulated-Layout-Width' UIToolbar:0x104fbbc90.width == 0 (active)>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x104fc2300 _UIButtonBarStackView:0x104fc0500.trailing == _UIToolbarContentView:0x104fbc760.trailing (active)> 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. willPresent notification: [AnyHashable("flag"): 1, AnyHashable("adtype"): 1, AnyHashable("gcm.message_id"): 0:1517497850922445%65857e1065857e10, AnyHashable("adid"): 1168, AnyHashable("aps"): { alert = { body = "\U10db\U10d0\U10da\U10d4!"; title = "\U10de\U10d8\U10ea\U10d0\U10d9\U10dd"; }; badge = 1; sound = default; }]
答案 0 :(得分:3)
它看起来不像你的错误。假设您的界面中没有发生任何不良事件,请将其报告给Apple并继续。