UIActivityViewController,在为 iOS 7.x 编译时在设备 8.x 上无法同时满足约束

2023-12-05

我有一个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 进行编译以实现兼容性。
The UIViewController使用使用自动布局的 .xib。但我尝试不使用自动布局,但出现了同样的问题。我在另外两个项目中尝试过,也在 iOS 7 上,但仍然是一样的。

我还尝试在呈现 ActivityViewController 之前添加此代码,但同样的问题:

[activityViewController.view setTranslatesAutoresizingMaskIntoConstraints:NO];

我看到其他开发者也有同样的问题(here)但这是由 Xcode 6 beta 引起的。我的是6.1版本


我猜这是 iOS7 的一个错误。 看起来有一些特殊的sourceRect价值。 您可以通过设置另一个来修复它sourceRect,例如您可以尝试:

[activityView popoverPresentationController].sourceRect=CGRectMake( 0,200,768,20);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

UIActivityViewController,在为 iOS 7.x 编译时在设备 8.x 上无法同时满足约束 的相关文章

随机推荐