[英]AutoLayout - Unable to simultaneously satisfy constraints in swift5
當您按下 web 視圖側邊欄上的按鈕時,會出現我的問題。 該按鈕向 web 視圖發送一條簡單消息並復制剪貼板。 Swift 將收到的消息顯示為敬酒。 這很簡單。
function似乎沒有問題,
但用戶界面是個問題。 按下按鈕時,屏幕從上到下滑動,顯示吐司,再次按下按鈕會激活按下側邊欄上另一個按鈕的 function。
屏幕是一樣的,但屏幕似乎是向下的。 側邊欄屏幕包含一個滾動條。 這就是它的意思嗎?
錯誤日志:
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:0x283a866c0 h=-&- v=-&- _UIToolbarContentView:0x133ebf3b0.width == UIToolbar:0x133ebef70.width (active)>",
"<NSLayoutConstraint:0x283a8b390 H:|-(0)-[_UIButtonBarStackView:0x133ec0570] (active, names: '|':_UIToolbarContentView:0x133ebf3b0 )>",
"<NSLayoutConstraint:0x283a8b3e0 _UIButtonBarStackView:0x133ec0570.trailing == _UIToolbarContentView:0x133ebf3b0.trailing (active)>",
"<NSLayoutConstraint:0x283a84910 H:|-(16)-[_UIModernBarButton:0x133dcc420] (active, names: '|':_UIButtonBarButton:0x133dcc1d0 )>",
"<NSLayoutConstraint:0x283a84960 H:[_UIModernBarButton:0x133dcc420]-(>=8)-| (active, names: '|':_UIButtonBarButton:0x133dcc1d0 )>",
"<NSLayoutConstraint:0x283a84f50 H:|-(>=5)-[_UIModernBarButton:0x133ecbe60] (active, names: '|':_UIButtonBarButton:0x133ecbc10 )>",
"<NSLayoutConstraint:0x283a84fa0 H:[_UIModernBarButton:0x133ecbe60]-(>=5)-| (active, names: '|':_UIButtonBarButton:0x133ecbc10 )>",
"<NSLayoutConstraint:0x283a856d0 H:|-(8)-[_UIModernBarButton:0x133dcd540'Done'] (active, names: '|':_UIButtonBarButton:0x133ecc380 )>",
"<NSLayoutConstraint:0x283a85720 H:[_UIModernBarButton:0x133dcd540'Done']-(16)-| (active, names: '|':_UIButtonBarButton:0x133ecc380 )>",
"<NSLayoutConstraint:0x283a85ae0 'UISV-canvas-connection' UILayoutGuide:0x2820c1c00'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x133dcc1d0.leading (active)>",
"<NSLayoutConstraint:0x283a85cc0 'UISV-canvas-connection' UILayoutGuide:0x2820c1c00'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x133ecc380.trailing (active)>",
"<NSLayoutConstraint:0x283a85d10 'UISV-spacing' H:[_UIButtonBarButton:0x133dcc1d0]-(0)-[UIView:0x133e94d90] (active)>",
"<NSLayoutConstraint:0x283a85d60 'UISV-spacing' H:[UIView:0x133e94d90]-(0)-[_UIButtonBarButton:0x133ecbc10] (active)>",
"<NSLayoutConstraint:0x283a85db0 'UISV-spacing' H:[_UIButtonBarButton:0x133ecbc10]-(0)-[UIView:0x133ecc1a0] (active)>",
"<NSLayoutConstraint:0x283a85e00 'UISV-spacing' H:[UIView:0x133ecc1a0]-(0)-[_UIButtonBarButton:0x133ecc380] (active)>",
"<NSLayoutConstraint:0x283a835c0 'UIView-Encapsulated-Layout-Width' UIToolbar:0x133ebef70.width == 0 (active)>",
"<NSLayoutConstraint:0x283a8b250 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x2820c1c00'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIButtonBarStackView:0x133ec0570 )>",
"<NSLayoutConstraint:0x283a8b2f0 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x2820c1c00'UIViewLayoutMarginsGuide']-(0)-|(LTR) (active, names: '|':_UIButtonBarStackView:0x133ec0570 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x283a84960 H:[_UIModernBarButton:0x133dcc420]-(>=8)-| (active, names: '|':_UIButtonBarButton:0x133dcc1d0 )>
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.
我真的很想解決這個問題。
這個按鈕的function和我通訊。 巴頓讓我給他看一條祝酒詞。
JS函數
function copy_address(){
var t = document.createElement("textarea");
document.body.appendChild(t);
t.value = $("#text").val();
t.select();
document.execCommand('copy');
document.body.removeChild(t);
var postData = {
tip: "testing",
message: "sucess",
timestamp: (new Date()).getTime().toString()
};
webkit.messageHandlers.send.postMessage(postData);
}
JSP 按鈕視圖
<div class="w" id="user"></div>
<div class="b-copy">
<button type="button" class="btn" onclick="copy_address()">copy</button>
<input type="text" id="copy_text" style="display: none;">
</div>
WebViewController 中的 Swift 代碼
import Toaster
...
override func loadView() {
super.loadView()
...
mainWebView = WKWebView(frame: mainWebView.frame, configuration: config)
mainWebView.uiDelegate = self
mainWebView.navigationDelegate = self
view.addSubview(mainWebView)
view.addSubview(indicatorImage)
}
@available(iOS 8.0, *)
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if message.name == "message" {
let sendmessage = message.body as! NSDictionary
guard sendmessage["val"] != nil else {
return
}
let val : String = sendmessage["val"] as! String
if sendmessage["val2"] != nil {
getmessage = sendmessage["val2"] as? String
}
switch val {
case "testing":
Toast(text: getmessage).show()
break
....
}
}
我通過模擬器發現了這個問題。
當我用我的實際 iPhone 進行檢查時,由於我看不到鍵盤,屏幕看起來像是從上到下往下掉的,但實際上只是看了一小會然后就消失了。
這就是工具欄高度有問題的原因。 鍵盤問題的原因是JS function。
t.select();
document.execCommand('copy');
由於這部分,鍵盤可見並消失了。 所以我通過搜索解決了這個問題。
t.readOnly = true;
我通過添加此代碼解決了我的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.