Add share button to full screen image view.

This commit is contained in:
Maurice Parker
2019-10-12 15:27:38 -05:00
parent 3ee0506b4a
commit 60fb58ecaa
3 changed files with 34 additions and 2 deletions

View File

@@ -10,10 +10,12 @@ import UIKit
class ImageViewController: UIViewController {
@IBOutlet weak var shareButton: UIButton!
@IBOutlet weak var activityIndicatorView: UIActivityIndicatorView!
@IBOutlet weak var imageScrollView: ImageScrollView!
private var dataTask: URLSessionDataTask? = nil
private var image: UIImage?
var url: URL!
override func viewDidLoad() {
@@ -29,9 +31,13 @@ class ImageViewController: UIViewController {
dataTask = URLSession.shared.dataTask(with: url) { [weak self] data, response, error in
guard let self = self else { return }
if let data = data, let image = UIImage(data: data) {
self.image = image
DispatchQueue.main.async {
self.shareButton.isEnabled = true
self.activityIndicatorView.isHidden = true
self.activityIndicatorView.stopAnimating()
self.imageScrollView.display(image: image)
@@ -44,7 +50,15 @@ class ImageViewController: UIViewController {
dataTask!.resume()
}
@IBAction func share(_ sender: Any) {
guard let image = image else { return }
let activityViewController = UIActivityViewController(activityItems: [url!, image], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = shareButton
present(activityViewController, animated: true)
}
@IBAction func done(_ sender: Any) {
dataTask?.cancel()
dismiss(animated: true)
}