简体   繁体   中英

iOS: Why the share of medias (images, videos or pdf) works on iPhone but not on iPad?

I have a piece of code that works very well on iPhone, but not on the iPad. It is like the window is there but not visible...

在此处输入图片说明

func userDidTapShare()
{
    print("Share")
    let mediaURL = URL(fileURLWithPath: Constants.Path.mainFolder.stringByAppendingPathComponent(path:mediaPath))
    let activityItems: [Any] = [mediaURL, "Check this out!"]

    let activityVC = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
    activityVC.popoverPresentationController?.sourceView = self.view
    activityVC.popoverPresentationController?.sourceRect = view.frame

    self.present(activityVC, animated: true, completion: nil)
}

The window doesn't present on the iPad.

Any idea?

Your sourceRect is an issue. Since it takes the entire screen (because you used the view frame), the popover is actually presented outside the frame of the screen.

For example, if you want it to show out of top left corner:

activityVC.popoverPresentationController?.sourceRect = CGRect(x: 0, y: 0, width: 1, height: 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM