0

我将 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];
}
4

1 回答 1

0

Of course, I find the resolution 5 seconds after I post this:

UIActivityViewController, Unable to simultaneously satisfy constraints, on devices 8.x when compiled for iOS 7.x

However, this is just bizarre... why would I need to set the source rect if I set the source View... shouldn't it derive from this somehow? I am assuming the sourceRect being set is simply causing the constraints to be ignored?

于 2020-06-03T15:54:41.790 回答