3

我正在尝试将自定义活动添加到我的 UIDocumentBrowserController 长按菜单 - UIActivityViewController。选中后,默认共享活动会很好地指向用户刚刚长按的文件图标。

如何获取 sourceRect 以便我的活动可以以类似的方式呈现?

let shareBundle = UIDocumentBrowserAction(identifier:
           "com.mycompany.myapp.shareBundle", localizedTitle: "Share with Data",
                availability: [.menu], handler: { urls in
            if urls.count > 0 {
                let objectsToShare: [URL] = [urls]
                let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
                activityVC.popoverPresentationController?.sourceView = self.view
                activityVC.popoverPresentationController?.sourceRect = // That's the problem!
                self.present(activityVC, animated: true, completion: nil)
            }
        })
4

1 回答 1

0

看起来目前无法查看所选文档的视图。

现在我最终只是将 ActivityView 定位在屏幕的中心并禁用箭头:

 if let popOverController = activityVC.popoverPresentationController {
      popOverController.sourceView = self.view
      popOverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
      popOverController.permittedArrowDirections = []
 }
于 2019-12-07T17:03:51.280 回答