可以通过以下简单项目重现该问题:
当用户单击导航栏上的+
按钮时,代码将实例化并以操作表样式显示UIAlertController
。
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func buttonTapped(_ sender: Any) {
let actionSheet = UIAlertController(title: nil,
message: nil,
preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Create Income",
style: .default) { _ in
print("Income!") })
actionSheet.addAction(UIAlertAction(title: "Create Outcome",
style: .default) { _ in
print("Outcome!")})
actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel) { _ in })
self.present(actionSheet, animated: true, completion: nil)
}
}
UI正确显示。问题是出现操作表时,Xcode会发出以下自动布局警告:
2020-03-12 11:24:57.002113+0800 alertcontroler_test[12757:936231] [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.
(
"<NSLayoutConstraint:0x600002d11b30 UIView:0x7f851961c560.width == - 16 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600002d11b30 UIView:0x7f851961c560.width == - 16 (active)>
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.
当操作表显示时,我检查Xcode中的UI层次结构,并发现一些子视图后带有感叹号:
我在Google上对此进行了搜索,但没有发现有人报告类似的问题(即UIAlertController
出现时的自动布局警告)。我找到一些有关如何在UIViewAlertForUnsatisfiableConstraints()
上设置断点以及如何调试汇编代码的信息。但是我认为这是UIAlertController
中的一个内部问题,我创建和展示UIAlertController
的方式是常见和典型的。有什么建议我应该做什么?
可以在最新版本的Xcode(11.3.1)和iOS(13.3)上找到。如果我将样式更改为警报,则问题不再存在。任何帮助将不胜感激。
答案 0 :(得分:2)
这是Apple团队无法修复的错误,该错误与与动画有关的警报和操作表有关。您可以点击以下链接进行验证:-
UIAlertController's actionSheet gives constraint error on iOS 12.2 / 12.3
Swift default AlertViewController breaking constraints
解决方案是将动画值传递为false,例如:-
GetProperty("AEVL2021")
我展示了没有动画的UIAlertController,警告消失了。
或者您可以尝试在stackoverflow的链接之一中提到的此解决方案:-
1Maria Del Mundo290
2Jay Del Mundo2220