2
ここに私のコードです。私は、ビューコントローラのトップレイアウトガイドの底に制約のWebViewアンカーの上部を作るしようとしているが、私はちょうどコンソールで黒い画面、時にはエラーを取得しています:アンカー/拘束をプログラムで使用するときにシミュレーションが空白の黒い画面になるのはなぜですか?
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)
(
"<_UILayoutSupportConstraint:0x608000284d30 _UILayoutSpacer:0x6080001aa560'UIVC-topLayoutGuide'.height == 20 (active)>",
"<_UILayoutSupportConstraint:0x6080002850a0 V:|-(0)-[_UILayoutSpacer:0x6080001aa560'UIVC-topLayoutGuide'] (active, names: '|':UIView:0x7fcfcac26cd0)>",
"<NSAutoresizingMaskLayoutConstraint:0x608000280fa0 h=--& v=--& WKWebView:0x7fcfcb09a400.midY == 0 (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x608000280ff0 h=--& v=--& WKWebView:0x7fcfcb09a400.height == 0 (active)>",
"<NSLayoutConstraint:0x6080002846f0 V:[_UILayoutSpacer:0x6080001aa560'UIVC-topLayoutGuide']-(3)-[WKWebView:0x7fcfcb09a400] (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x608000281220 h=--& v=--& 'UIView-Encapsulated-Layout-Top' UIView:0x7fcfcac26cd0.minY == 0 (active, names: '|':UIViewControllerWrapperView:0x7fcfcac08120)>"
)
コード -
import UIKit
import WebKit
class webViewController: UIViewController, WKNavigationDelegate {
override func loadView() {
self.view = UIView()
let webView = WKWebView()
// webView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(webView)
let topConstraint = webView.topAnchor.constraint(equalTo: self.topLayoutGuide.bottomAnchor, constant: 3)
topConstraint.isActive = true
let url = NSURL(string: "https://www.google.com")
if let selectedURL = url {
let request = NSURLRequest(url: selectedURL as URL) as URLRequest
webView.load(request)
}
}
}
どの制約が自動的に壊れたのかわからず、これで問題が解決しない場合は、追加してください - いくつかのNSAutoResizingMaskLayoutConstraintの問題に気づいています。そのマスクを各ビューに対して** false **に設定する必要があります。 – dfd
ごめん、ロハン...何を追加しますか?コメントアウトされた行? – user7024499
私はあなたがそれをコメントアウトしたのを見なかった。繰り返しますが、それでも問題が解決しない場合は、制約ダンプ(何をやったのですか?)と設定したその他の制約を** **両方に加えてください。 – dfd