UIAlertController 的 actionSheet 报约束错误

19-08-27 15:19 字数 1404 阅读 3718 已编辑

模拟器版本:12.4
Xcode 版本:10.3

我使用 UIAlertController 创建了一个 actionSheet,在弹出的时候,会报一个约束错误

我的代码如下

let alertController = UIAlertController(title: nil, message: "选择操作", preferredStyle: .actionSheet)
let shareAction = UIAlertAction(title: "分享到微信", style: .default) { _ in
        print("点击分享到微信")
}
let webviewAction = UIAlertAction(title: "浏览器打开", style: .default) { _ in
        print("点击浏览器打开")
}
let copyLinkAction = UIAlertAction(title: "复制链接", style: .default) { _ in
        print("点击复制链接")
}
let cancelAction = UIAlertAction(title: "取消", style: .cancel) { _ in
        print("点击了取消")
}
alertController.addAction(shareAction)
alertController.addAction(webviewAction)
alertController.addAction(copyLinkAction)
alertController.addAction(cancelAction)
present(alertController, animated: true, completion: nil)

报错信息如下

2019-08-27 15:01:05.571083+0800 SHIQIDU[22849:4109766] [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:0x600000d6d2c0 UIView:0x7faa9ce60380.width == - 16   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000d6d2c0 UIView:0x7faa9ce60380.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.

报错

不知道为什么出现这种情况,后来网上查询原来是个 bug,从 iOS 12.1 开始就有这个毛病,到现在还没修复。

https://stackoverflow.com/questions/55372093/uialertcontrollers-actionsheet-gives-constraint-error-on-ios-12-2-12-3

1人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论
站长 @ 十七度
文章
384
粉丝
23
喜欢
195
收藏
31
排名 : 1
访问 : 147.29万
私信