最佳答案
我试图使用样式 。行动表的默认 AlertViewController。由于某种原因,警报会导致 约束错误。只要不通过按钮触发(显示) AlertController,整个视图就不会出现约束错误。这会不会是 Xcode 的 bug?
我得到的确切错误如下:
2019-04-12 15:33:29.584076+0200 Appname[4688:39368] [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:0x6000025a1e50 UIView:0x7f88fcf6ce60.width == - 16 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000025a1e50 UIView:0x7f88fcf6ce60.width == - 16 (active)>
这是我使用的代码:
@objc func changeProfileImageTapped(){
print("ChangeProfileImageButton tapped!")
let alert = UIAlertController(title: "Change your profile image", message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Photo Library", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Online Stock Library", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
alert.view.tintColor = ColorCodes.logoPrimaryColor
self.present(alert, animated: true)
}
正如你所看到的,它是 非常简单。这就是为什么我非常困惑的奇怪行为,我得到的这个 默认实现应该不会导致任何错误,对不对?
尽管如此,通过打破这些限制,警报在所有屏幕尺寸上都能正常显示,如果能得到任何帮助,我将非常感激。