UIActivityViewController has a weird size and shape

Viewed 1692

I just got this bug report for me app...the activity view controller is suddenly this weird narrow shape whether I'm on an actual phone or the view controller.

Narrow view controller

This is happening with some plain vanilla code that hasn't been touched in months:

UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[message] applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];

What could be going wrong? I can't even think of where to start troubleshooting this one.

9 Answers

I can reproduce this on iOS 12 when:

  1. The controller that is presenting the activityViewController (self in this case) is itself presented with UIModalPresentationOverFullScreen
  2. Somewhere in the presentation chain beneath self, there is another UIActivityAlertViewController.

The solution in my case is to switch self back to UIModalPresentationFullScreen.

In iPadOS you have to set the PopoverPresentationController's Source View and Source Rect properties. The following code will make it so the ActivityViewController comes from the center of the screen with the default size

For Swift 5

activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.size.width / 2.0, y: self.view.bounds.size.height-50, width: 1.0, height: 1.0)

We would need to set the sourceView and sourceRect (optional but may needed to be set for iPad).

We may try below snippet

activityViewController.popoverPresentationController?.sourceView = sender.self
activityViewController.popoverPresentationController?.sourceRect = sender.frame
Related