如何在 Swift 中创建类似 Android 的共享选项 [重复]
Posted
技术标签:
【中文标题】如何在 Swift 中创建类似 Android 的共享选项 [重复]【英文标题】:How to create share options like on Android in Swift [duplicate] 【发布时间】:2018-10-29 05:29:43 【问题描述】:我需要显示一个选项来分享一些细节,比如在 android 上使用 Swift。 如何在屏幕上显示要共享的应用程序列表? 请看下面的截图:
【问题讨论】:
Add sharing to your Swift app via UIActivityViewController, How to share content with UIActivityViewController, UIActivityViewController by example, How To Share Content With UIActivityViewController 【参考方案1】:试试这样的:
private func shareWhatYouWant()
//pop invite view
var textToShare = "Your message"
if let myWebsite = NSURL(string: "Yourwebsite.com")
let objectsToShare = [textToShare, myWebsite] as [Any]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
//New Excluded Activities Code
activityVC.completionWithItemsHandler =
activity, sucess, items, error in
if !sucess
print("cancelled")
return
if activity == UIActivityType.postToFacebook
print("share on facebook")
if activity == UIActivityType.postToTwitter
print("share on twitter")
if activity == UIActivityType.message
print("share on message")
if activity == UIActivityType.addToReadingList
print("air drop select")
activityVC.popoverPresentationController?.sourceView = sender as? UIView
self.present(activityVC, animated: true, completion: nil)
【讨论】:
以上是关于如何在 Swift 中创建类似 Android 的共享选项 [重复]的主要内容,如果未能解决你的问题,请参考以下文章
如何在 swift 中创建像 tinder 这样的堆栈视图? [关闭]
如何在 Android 中创建类似于“选项卡布局”的圆形数组?