【问题标题】:UIDocumentMenuViewController showing on iPad gives "Unable to simultaneously satisfy constraints"在 iPad 上显示的 UIDocumentMenuViewController 给出“无法同时满足约束”
【发布时间】:2014-12-18 18:19:26
【问题描述】:

我在从 iPad 上的条形按钮项目中显示 UIDocumentMenuViewController 时遇到了一些问题。我确实得到了正确的初始行为,并且根据需要从 barButtonItem 调用了菜单,但是在调用委托之前,我收到了一些我不确定如何修复的自动布局约束消息。这就是我调用 UIDocumentMenu VC 的方式:

UIDocumentMenuViewController *documentMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:[self fileUTIList] inMode:UIDocumentPickerModeImport];
documentMenu.delegate = self;
documentMenu.modalPresentationStyle = UIModalPresentationPopover;
documentMenu.popoverPresentationController.barButtonItem = self.rightAddButton;
//documentMenu.popoverPresentationController.sourceView = self.view;
//documentMenu.should have a non-nil sourceView or barButtonItem set before the presentation occurs
[self presentViewController: documentMenu animated:YES completion: ^{
    NSLog(@"DocumentPicker presented completion");
}];

我得到上述完成处理程序被正确调用,并且在 iPad 上看起来很好。但是当我为菜单选择一个项目时,我立即收到“无法同时满足约束”的消息:

2014-10-22 22:42:20.817 iPad[34421:474588] 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:0x7c1d0f30 H:[UIView:0x7c1cbc20(304)]>",
    "<NSLayoutConstraint:0x7c1ddbf0 _UIAlertControllerView:0x7c1cbc90.width == UIView:0x7c1ca670.width>",
    "<NSLayoutConstraint:0x7c14b310 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7c1ca670(142)]>",
    "<NSLayoutConstraint:0x7c151a80 _UIAlertControllerView:0x7c1cbc90.width >= UIView:0x7c1cbc20.width>"
)

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

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2014-10-22 22:42:20.818 iPad[34421:474588] documentMenu: didPickDocumentPicker

然后最终调用了 documentMenu 的委托,呈现了 UIDocumentPickerViewController,看起来是正确的:

- (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker {
NSLog(@"documentMenu: didPickDocumentPicker");
documentPicker.delegate = self;
[self presentViewController:documentPicker animated:YES completion:nil];

但我担心,如果我附带这个,这会产生影响并导致一些奇怪的显示问题。有什么方法可以确定究竟是什么导致了这种行为,因为它似乎来自 UIDocumentMenuViewController / UIAlertControllerView?

【问题讨论】:

  • 遗憾的是,这不是一个答案,但值得一提的是,Apple 的 Lister 示例代码(Swift 变体)在 iOS 8.1 + Xcode 6.1 上一直向我发出非常相似的警告
  • objective-c 版本也是如此。估计是内部问题我将我的更新推送到了 App Store,到目前为止似乎没有人抱怨这个问题。

标签: ipad uikit autolayout icloud uialertcontroller


【解决方案1】:

iPad 有一些关于 ActionSheets 及其取消按钮的特殊规则,这通常取决于您从哪里显示 ActionSheets,因此您可以通过以下方式解决崩溃问题:

let importMenu = UIDocumentMenuViewController(documentTypes: [kUTTypeHTML as String ], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .popover
importMenu.popoverPresentationController?.sourceView = self.view
self.present(importMenu, animated: true, completion: nil)

【讨论】:

  • 我已经做到了这一点,我在 iOS 11.4 中遇到了崩溃。
  • 崩溃说明了什么?
  • 我只是通过删除sourceView 行并指定barButtonItem 来修复它,如下所示:documentProvider.popoverPresentationController?.barButtonItem = self.buttonRestore
【解决方案2】:

在显示 documentMenu 之前尝试添加:

[documentMenu.view setTranslatesAutoresizingMaskIntoConstraints:NO];

【讨论】:

  • 我遇到了同样的问题,这解决了问题。
  • 我提交了一个可能会被骗的雷达:openradar.appspot.com/19385063
  • 这并不能解决我的问题(iOS 9.3.1 和 iPhone 6/6s)。我已经复制了@cescofry 雷达。
  • 前段时间我添加了那行来修复一个错误。然而,在 iOS 10 beta 4 和 5 中,它会导致一个更严重的错误:UIDocumentMenuViewController 会显示一个空白菜单。
  • 没用!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-09
  • 2012-12-28
  • 1970-01-01
  • 2014-10-27
  • 2014-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多