2019-10-12 14:45:44 -05:00
|
|
|
//
|
|
|
|
// ImageViewController.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 10/12/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
class ImageViewController: UIViewController {
|
|
|
|
|
2019-10-12 15:27:38 -05:00
|
|
|
@IBOutlet weak var shareButton: UIButton!
|
2019-10-12 14:45:44 -05:00
|
|
|
@IBOutlet weak var imageScrollView: ImageScrollView!
|
|
|
|
|
2019-10-13 19:41:34 -05:00
|
|
|
var image: UIImage!
|
2019-10-15 18:08:13 -05:00
|
|
|
var zoomedFrame: CGRect {
|
|
|
|
return imageScrollView.zoomedFrame
|
|
|
|
}
|
2019-10-12 14:45:44 -05:00
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
imageScrollView.setup()
|
|
|
|
imageScrollView.imageScrollViewDelegate = self
|
|
|
|
imageScrollView.imageContentMode = .aspectFit
|
|
|
|
imageScrollView.initialOffset = .center
|
2019-10-13 19:41:34 -05:00
|
|
|
imageScrollView.display(image: image)
|
2019-10-12 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
2019-10-16 20:20:36 -05:00
|
|
|
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
|
|
|
super.viewWillTransition(to: size, with: coordinator)
|
|
|
|
coordinator.animate(alongsideTransition: { [weak self] context in
|
|
|
|
self?.imageScrollView.resize()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-10-12 15:27:38 -05:00
|
|
|
@IBAction func share(_ sender: Any) {
|
|
|
|
guard let image = image else { return }
|
2019-10-13 19:41:34 -05:00
|
|
|
let activityViewController = UIActivityViewController(activityItems: [image], applicationActivities: nil)
|
2019-10-12 15:27:38 -05:00
|
|
|
activityViewController.popoverPresentationController?.sourceView = shareButton
|
2019-10-12 16:54:24 -05:00
|
|
|
activityViewController.popoverPresentationController?.sourceRect = shareButton.bounds
|
2019-10-12 15:27:38 -05:00
|
|
|
present(activityViewController, animated: true)
|
|
|
|
}
|
|
|
|
|
2019-10-12 14:45:44 -05:00
|
|
|
@IBAction func done(_ sender: Any) {
|
|
|
|
dismiss(animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: ImageScrollViewDelegate
|
|
|
|
|
|
|
|
extension ImageViewController: ImageScrollViewDelegate {
|
|
|
|
|
|
|
|
func imageScrollViewDidGestureSwipeUp(imageScrollView: ImageScrollView) {
|
|
|
|
dismiss(animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func imageScrollViewDidGestureSwipeDown(imageScrollView: ImageScrollView) {
|
|
|
|
dismiss(animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|