我有一个 UIActivityViewController 显示在 UIViewController 上(此处命名为 viewCon):
// items contains text and/or image
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact];
[viewCon presentViewController:activityViewController animated:YES completion:NULL];
我使用的是 Xcode 6.1。我的应用程序的部署目标为 7.0。我在两部物理 iPhone(5S (8.0.2) 和 6 (8.1))上运行它。
当我在物理设备(而不是模拟器)上为 iOS 7.x 编译我的应用程序时,UIActivityViewController 会显示并且可以工作,但它会出现在所有屏幕上(高度太大)和此日志消息打印在输出中:
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:0x1742941e0 UIView:0x174385960.bottom == _UIAlertControllerView:0x134ef4fc0.bottom>",
"<NSLayoutConstraint:0x174293d80 V:|-(0)-[UIView:0x170385960] (Names: '|':_UIAlertControllerView:0x134ef4fc0 )>",
"<NSLayoutConstraint:0x17429a270 UIView:0x170385960.bottom <= _UIAlertControllerView:0x134ef4fc0.bottom>",
"<NSLayoutConstraint:0x174292cf0 UIView:0x174385960.centerY == UIView:0x170385960.centerY>",
"<NSLayoutConstraint:0x174294410 V:|-(>=8)-[UIView:0x174385960] (Names: '|':_UIAlertControllerView:0x134ef4fc0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17429a270 UIView:0x170385960.bottom <= _UIAlertControllerView:0x134ef4fc0.bottom>
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.
当我为 iOS 8.x 编译和运行时,一切正常。但是为了兼容,我当然需要为 iOS 7.x 编译。
UIViewController 使用一个使用 Autolayout 的 .xib。但是我尝试不使用 Autolayout 并且出现了同样的问题。我尝试了另外两个项目,也在 iOS 7 上,它仍然是一样的。
我也尝试在展示 activityViewController 之前添加此代码,但同样的问题:
[activityViewController.view setTranslatesAutoresizingMaskIntoConstraints:NO];
我看到其他开发人员也有同样的问题 (here),但这是由 Xcode 6 beta 引起的。我有 6.1 版。
Best Answer-推荐答案 strong>
我猜这是 iOS7 的错误。
它带有一些特殊的 sourceRect 值。
您可以通过设置另一个 sourceRect 来修复它,例如您可以尝试:
[activityView popoverPresentationController].sourceRect=CGRectMake( 0,200,768,20);
关于ios - UIActivityViewController,在为 iOS 7.x 编译时在设备 8.x 上无法同时满足约束,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/26623893/
|