我一直在使用下面的代码来显示UIActivityViewController,当我使用Xcode 6、Swift 1.2和iOS 8时,它工作得很好。然而,当我更新它时,它显示了UIActivityViewController,但是它是完全空白的,没有任何共享选项。你有什么意见建议?
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
let textToShare = textViewOne.text
let objectsToShare = [textToShare]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
let nav = UINavigationController(rootViewController: activityVC)
nav.modalPresentationStyle = UIModalPresentationStyle.Popover
let popover = nav.popoverPresentationController as UIPopoverPresentationController!
popover.sourceView = self.view
popover.sourceRect = sender.frame
self.presentViewController(nav, animated: true, completion: nil)
} else {
let textToShare = textViewOne.text
let objectsToShare = [textToShare]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)
}发布于 2015-10-03 14:27:36
这个已经修好了。
let objectsToShare = [textToShare]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.title = "Share One"
activityVC.excludedActivityTypes = []
activityVC.popoverPresentationController?.sourceView = self.view
activityVC.popoverPresentationController?.sourceRect = sender.frame
self.presentViewController(activityVC, animated: true, completion: nil)迅速3.0版:
let objectsToShare = [textToShare]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.title = "Share One"
activityVC.excludedActivityTypes = []
activityVC.popoverPresentationController?.sourceView = self.view
activityVC.popoverPresentationController?.sourceRect = sender.frame
self.present(activityVC, animated: true, completion: nil)发布于 2020-10-14 09:47:34
我与SWIFT 5公司的上述建议斗争,因为:
activity.popoverPresentationController?.sourceRect = sender.frame
在某些情况下不工作,因为发送方在作用域上不可用。相反,尝试使用CGRECT设置,如下所示:
activityController.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY,width: 0,height: 0)我希望这能帮到一些人。
发布于 2018-10-27 12:45:53
Swift 4.0
let shareText = "Hi"
let activity = UIActivityViewController(activityItems: shareText, applicationActivities: nil)
activity.excludedActivityTypes = []
if UIDevice.current.userInterfaceIdiom == .pad {
activity.popoverPresentationController?.sourceView = self.view
activity.popoverPresentationController?.sourceRect = sender.frame
}
self.present(activity, animated: true, completion: nil)https://stackoverflow.com/questions/32889680
复制相似问题