mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-15 10:49:14 +01:00
66 lines
1.7 KiB
Swift
66 lines
1.7 KiB
Swift
//
|
|
// ImageViewController.swift
|
|
// NetNewsWire-iOS
|
|
//
|
|
// Created by Maurice Parker on 10/12/19.
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class ImageViewController: UIViewController {
|
|
|
|
@IBOutlet weak var shareButton: UIButton!
|
|
@IBOutlet weak var imageScrollView: ImageScrollView!
|
|
|
|
var image: UIImage!
|
|
var zoomedFrame: CGRect {
|
|
return imageScrollView.zoomedFrame
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
imageScrollView.setup()
|
|
imageScrollView.imageScrollViewDelegate = self
|
|
imageScrollView.imageContentMode = .aspectFit
|
|
imageScrollView.initialOffset = .center
|
|
imageScrollView.display(image: image)
|
|
}
|
|
|
|
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()
|
|
})
|
|
}
|
|
|
|
@IBAction func share(_ sender: Any) {
|
|
guard let image = image else { return }
|
|
let activityViewController = UIActivityViewController(activityItems: [image], applicationActivities: nil)
|
|
activityViewController.popoverPresentationController?.sourceView = shareButton
|
|
activityViewController.popoverPresentationController?.sourceRect = shareButton.bounds
|
|
present(activityViewController, animated: true)
|
|
}
|
|
|
|
@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)
|
|
}
|
|
|
|
|
|
}
|