提问人:Speckpgh 提问时间:6/3/2020 更新时间:6/3/2020 访问量:316
IPAD 从 UIAlertController 样式呈现 UIActivityViewController UIAlertControllerActionSheet“无法同时满足约束”
IPAD Presenting a UIActivityViewController from a UIAlertController style UIAlertControllerActionSheet "unable to simultaneously satisfy constraints"
问:
我将 UIAlertController 作为操作表呈现,其中包含一个按钮,该按钮在选中时应打开 ActivityView。
这两种方法都在同一个 ViewController 类中...并且可以在 iphone 8、iPhone Pro 11 Max 等上运行良好。但在 iPad 上测试时失败。(全部运行 13.5)
最初的失败是 popoverPresentationController 没有设置 sourceview 或 barbuttonitem(或类似的东西),所以我添加了以下行:
activityViewController.popoverPresentationController.sourceView = [self view];
到 share 方法。这让我度过了难关......因此,现在 IPAD 不会因 GenericException 而崩溃。但它也从不显示 activityView。它只是抛出一堆约束冲突,这些冲突似乎与尝试显示的 ActivityView 有关,
[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:0x6000000d2580 LPLinkView:0x7fda08498900.leading == UILayoutGuide:0x600001a39dc0'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x6000000d23f0 H:[LPLinkView:0x7fda08498900]-(59)-| (active, names: '|':_UIActivityContentTitleView:0x7fda08493b90 )>",
"<NSLayoutConstraint:0x6000000cf660 H:|-(0)-[_UIActivityContentTitleView:0x7fda08493b90] (active, names: '|':_UINavigationBarContentView:0x7fda085d5550 )>",
"<NSLayoutConstraint:0x6000000cf6b0 _UIActivityContentTitleView:0x7fda08493b90.trailing == _UINavigationBarContentView:0x7fda085d5550.trailing (active)>",
"<NSLayoutConstraint:0x6000000d08c0 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x7fda085d5550.width == 0 (active)>",
"<NSLayoutConstraint:0x6000000d2260 'UIView-leftMargin-guide-constraint' H:|-(16)-[UILayoutGuide:0x600001a39dc0'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIActivityContentTitleView:0x7fda08493b90 )>"
)
但我对此没有任何限制..以及关于引用我的应用程序没有或使用的导航栏的投诉区域。这些限制必须来自某些默认设置,这些设置仅与 IPAD 相关。有谁知道我需要在这里做些什么才能在IPAD上解决这个问题?为什么默认约束与我从未设置过的东西有关..我只设置了sourceView。
-(UIAlertController *)displayActionSheet
{
UIAlertController *sheet = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
.
.
.
UIAlertAction *share = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Share with Friends", @"Share with Friends")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action){
[self share];
}];
[sheet addAction:share];
.
.
.
[sheet popoverPresentationController].sourceView = [self view];
sheet.popoverPresentationController.permittedArrowDirections = 0;
[sheet popoverPresentationController].sourceRect = CGRectMake(view.bounds.size.width/2, view.bounds.size.height/2, 0, 0);
[self presentViewController:sheet animated:YES completion:nil];
return sheet;
}
-(void)share
{
NSString *shareString = @"a string to share";
UIImage *shareImage = [UIImage imageNamed:@"animagetoshare"];
NSURL *shareUrl = [NSURL URLWithString:@"a url to share"];
NSArray *activityItems = [NSArray arrayWithObjects:shareString, shareImage, shareUrl, nil];
UIActivityViewController *activityViewController = [[[UIActivityViewController alloc]
initWithActivityItems:activityItems applicationActivities:nil] autorelease];
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
activityViewController.excludedActivityTypes = @[UIActivityTypePrint,
UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList];
activityViewController.popoverPresentationController.sourceView = [self view];
[self presentViewController:activityViewController animated:YES completion:nil];
}
答:
0赞
Speckpgh
6/3/2020
#1
当然,我在发布此消息后 5 秒找到了解决方案:
UIActivityViewController,针对 iOS 7.x 编译时,无法同时满足设备 8.x 上的约束
然而,这太奇怪了......如果我设置源 View,为什么我需要设置源矩形...它不应该以某种方式衍生出来吗?我假设设置的 sourceRect 只是导致约束被忽略?
评论