ios - UIAlertController 无法满足约束

标签 ios objective-c iphone uiactionsheet uialertcontroller

我正在用 UIAlertController 转换我所有的 UIActionSheetUIAlertView

我的问题是当我尝试呈现 ActionSheet 样式的 UIAlertController 时。 这是我的代码:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title"
                                                               message:@"My message"
                                                        preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancelAction];

UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:OKAction];

UIAlertAction *destroyAction = [UIAlertAction actionWithTitle:@"Destroy" style:UIAlertActionStyleDestructive handler:nil];
[alert addAction:destroyAction];

UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
popPresenter.sourceView = self.view;
popPresenter.sourceRect = self.view.bounds;

[self presentViewController:alert animated:YES completion:nil];

这里是错误:

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) 
(
    "<NSLayoutConstraint:0x7c00ab40 H:[UIView:0x7c0764c0(304)]>",
    "<NSLayoutConstraint:0x7b6c7f80 _UIAlertControllerView:0x7b6c2e50'title'.width >= UIView:0x7b6c3230.width>",
    "<NSLayoutConstraint:0x7ccdfe40 _UIAlertControllerView:0x7b6c2e50'title'.width == UIView:0x7b6efbe0.width>",
    "<NSAutoresizingMaskLayoutConstraint:0x7c33b9d0 h=--& v=--& H:[UIView:0x7c1094e0(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7c00ab40 H:[UIView:0x7c0764c0(304)]>

谢谢大家

最佳答案

我在呈现 ActionSheet 样式的 UIAlertController 时也遇到了类似的问题。

另一个可能的原因是错误地设置了 UIPopoverPresentationControllerpermittedArrowDirections。在我的例子中,弹出窗口的 sourceView 位于顶部,但我已将 permittedArrowDirections 设置为 UIPopoverArrowDirectionDown,这会导致“无法同时满足约束”错误。在我将其设置为 UIPopoverArrowDirectionUp 后,错误消失了。

关于ios - UIAlertController 无法满足约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33437359/

相关文章:

ios - 使用 XHFaceMaskSDKSimple 在检测到的面部上设置 UIImage,无法添加演示中静态添加的图像

iphone - 什么是 XMPP,如何在 iOS 聊天应用程序中使用它?

iphone - 这个pushViewController语句在我正在做的教程中如何工作?

iphone - CABasicAnimation 在 3G 上比在 4/4S/ipod4 上快得多

ios - 未在 catch block 中处理的异常

ios - 如何使用prepareForSegue从UIButton传递字符串

iphone - 更改 UIPickerView 中两个不同组件中的行

ios - NSAttributedString 行尾的 NSKernAttributeName 空格

objective-c - Xcode 链接器错误 : file too small for architecture x86_64

ios - 是否可以在 JSON 数据中搜索特定键?