【发布时间】:2019-05-21 07:19:26
【问题描述】:
我正在开发与默认“照片”应用相同的照片共享按钮。
当我点击分享按钮时,它会作为子视图 (uiactivityviewcontroller/uiactivityviewcontroller.view) 添加到我的视图控制器中?
我的代码:
let text = "This is some text that I want to share."
// set up activity view controller
let textToShare = [ text ]
let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil)
// exclude some activity types from the list (optional)
//activityViewController.excludedActivityTypes = [ .airDrop,.postToFacebook ]
// present the view controller
if (UIDevice.current.userInterfaceIdiom == .phone){
self.containerView.addSubview(activityViewController.view)
}else{
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
self.present(activityViewController, animated: true, completion: nil)
}
但是这段代码给了我错误UIActivityViewController 只能以模态方式使用,或者在 iPad 上的弹出窗口中用作 contentViewController。
有没有更好的解决方案?
提前致谢。
【问题讨论】:
-
您的应用程序 rootVC 是否嵌入了 NavigationController?
-
@karthikeyan 是的
标签: ios swift uiactivityviewcontroller