0
votes

I have a UIActivityViewController that I am presenting in a popover on the iPad (using a UIPopoverPresentationController).

When the popover is shown initially, its size is correct. When I tap 'More', a 'Activities' view is presented. When I tap 'Done', the UIActivityViewController doesn't resize to its initial size and the content within the UIActivityViewController unfortunately doesn't take up the entire view.

Here is the steps taken:

Display the UIActivityViewController: enter image description here

Tap on the 'More' button: enter image description here

The popover expands in order to prevent the text from being cut off.

Tap on the 'Done' button on the navigationBar: enter image description here

The popover doesn't resize again to what its initial size was.

The code in creating and showing the UIActivityViewController:

- (void)actionButtonTapped:(id)sender {
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[self.pdfSummary] applicationActivities:nil];

BOOL canSendMail = [MFMailComposeViewController canSendMail];
NSMutableArray *excluded = [@[UIActivityTypeAddToReadingList,
        UIActivityTypeAssignToContact,
        UIActivityTypeCopyToPasteboard,
        UIActivityTypeMessage,
        UIActivityTypePostToFacebook,
        UIActivityTypePostToFlickr,
        UIActivityTypePostToTencentWeibo,
        UIActivityTypePostToTwitter,
        UIActivityTypePostToVimeo,
        UIActivityTypePostToWeibo,
        UIActivityTypeSaveToCameraRoll] mutableCopy];
if (!canSendMail) {
    [excluded addObject:UIActivityTypeMail];
}
activityViewController.excludedActivityTypes = excluded;

[self showActivityViewController:activityViewController fromBarButtonItem:sender];

}

And the showActivityViewController method looks something like:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:activityViewController];
navController.modalPresentationStyle = UIModalPresentationPopover;
navController.navigationBarHidden = YES;

UIPopoverPresentationController *popoverPresentationController = [navController popoverPresentationController];

popoverPresentationController.permittedArrowDirections = arrowDirection;
popoverPresentationController.barButtonItem = buttonItem;

[self presentViewController:navController animated:YES completion:nil];

return popoverPresentationController;

Is there any workaround for this. Resizing the popover or just keeping it one size?

I have tried subclassing UIActivityViewController and changing the preferredContentSize, but the UIActivityController's content wouldn't resize to fit the popover's size

1
If I remember correctly, you need to display this popover from the topmost view controller. I also think you need to dismiss it from the completion handler of the delegate. How are you dismissing the popover? - fsb
You should not be creating your own nav controller or popover to display a UIActivityViewController. - rmaddy
Currently @fbara it is being dismissed when tapping outside of it, or when an item in the list has been selected, but dismissing it is not the problem here. - user3253063
How should one go about displaying UIActivityViewController in a popover on the iPad @rmaddy? - user3253063
Get the popoverPresentationController directly from the UIActivityViewController and set its barButtonItem. - rmaddy

1 Answers

0
votes

Don't put the activity controller into a navigation controller. Directly use the popover from the activity controller.

You can update your showActivityViewControlleras follows:

UIPopoverPresentationController *popoverPresentationController = [activityViewController popoverPresentationController];

popoverPresentationController.permittedArrowDirections = arrowDirection;
popoverPresentationController.barButtonItem = buttonItem;

[self presentViewController:activityViewController animated:YES completion:nil];