iOS:为什么共享媒体(图片、视频或 pdf)在 iPhone 上有效,但在 iPad 上无效?

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

我有一段代码在 iPhone 上运行良好,但在 iPad 上运行不佳。就像 window 在那里但不可见...

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)
}

window 没有出现在 iPad 上。

有什么想法吗?

你的 sourceRect 是个问题。由于它占据了整个屏幕(因为您使用了视图框架),因此弹出窗口实际上呈现在屏幕框架之外。

例如,如果您希望它显示在左上角之外:

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