我将UIAlertController呈现为操作表,并带有一个按钮,当选择该按钮时应打开一个ActivityView...。
这两种方法都在同一个ViewController类中……并且可以在iphone 8,iPhone Pro 11 Max等上正常工作。但是在iPad上测试时失败。 (全部运行13.5)
最初的失败是popoverPresentationController没有设置sourceview或barbuttonitem(或类似的东西,所以我添加了这一行:
activityViewController.popoverPresentationController.sourceView = [self view];
分享方法。这让我超越了过去……所以,现在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];
}
当然,发布此消息5秒钟后我会找到分辨率:
但是,这只是奇怪的...如果设置源视图,为什么我需要设置源rect ...它不应该以某种方式衍生吗?我假设正在设置sourceRect只是导致约束被忽略?