使用 UIActivityViewController 共享图像
Posted
技术标签:
【中文标题】使用 UIActivityViewController 共享图像【英文标题】:Share an image using UIActivityViewController 【发布时间】:2015-03-22 21:34:28 【问题描述】:我想使用UIActivityViewController
分享图像。我能够显示我想分享的文本,但我真的不知道如何添加图像。希望有人可以帮助我。谢谢!
我的代码显示在“actionButton”下
import UIKit
class DetailViewController: UIViewController, UIScrollViewDelegate
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var myDetailedImageView: UIImageView!
var myDetailedImageName: String?
var nameString: String?
override func prefersStatusBarHidden() -> Bool
return true
override func viewDidLoad()
super.viewDidLoad()
//For setting max and min zoom
scrollView.maximumZoomScale = 0.8
scrollView.minimumZoomScale = 0.15
scrollView.delegate = self
//reset zoomzcale for new image
self.scrollView.zoomScale = 0.15
self.myDetailedImageView.image = UIImage(named: myDetailedImageName!)
@IBAction func actionButton(sender: AnyObject)
let firstActivityItem = NSString(string: myDetailedImageName!)
let activityViewController : UIActivityViewController = UIActivityViewController(activityItems: [firstActivityItem], applicationActivities: nil)
self.presentViewController(activityViewController, animated: true, completion: nil)
//Showing what to zoom/scroll
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView?
//returning image to reload it self
return myDetailedImageView
override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
【问题讨论】:
【参考方案1】:就像文字一样:
let activityViewController = UIActivityViewController(activityItems: [firstActivityItem, self.myDetailedImageView.image!], applicationActivities: nil)
【讨论】:
它仍然给我一个错误说:不能使用类型为“(activityitems:$T4,applicationActivities:NilLiteralConveritble)”的参数列表调用“init” @MariusHegg 请查看编辑后的答案 (self.myDetailedImageView.image!
)以上是关于使用 UIActivityViewController 共享图像的主要内容,如果未能解决你的问题,请参考以下文章
在使用加载数据流步骤的猪中,使用(使用 PigStorage)和不使用它有啥区别?