Enhance full image view support to work with 3 panel mode and split window views

This commit is contained in:
Maurice Parker 2019-10-16 20:20:36 -05:00
parent 6c562f93b5
commit eca5f8259a
5 changed files with 337 additions and 341 deletions

View File

@ -444,11 +444,7 @@ private extension ArticleViewController {
transition.maskFrame = webView.convert(webView.frame, to: nil)
transition.originImage = image
let imageVC = UIStoryboard.main.instantiateController(ofType: ImageViewController.self)
imageVC.image = image
imageVC.modalPresentationStyle = .fullScreen
imageVC.transitioningDelegate = self
present(imageVC, animated: true)
coordinator.showFullScreenImage(image: image, transitioningDelegate: self)
}
}

View File

@ -9,7 +9,6 @@
import UIKit
@objc public protocol ImageScrollViewDelegate: UIScrollViewDelegate {
func imageScrollViewDidChangeOrientation(imageScrollView: ImageScrollView)
func imageScrollViewDidGestureSwipeUp(imageScrollView: ImageScrollView)
func imageScrollViewDidGestureSwipeDown(imageScrollView: ImageScrollView)
}
@ -72,18 +71,12 @@ open class ImageScrollView: UIScrollView {
initialize()
}
deinit {
NotificationCenter.default.removeObserver(self)
}
private func initialize() {
showsVerticalScrollIndicator = false
showsHorizontalScrollIndicator = false
bouncesZoom = true
decelerationRate = UIScrollView.DecelerationRate.fast
delegate = self
NotificationCenter.default.addObserver(self, selector: #selector(ImageScrollView.changeOrientationNotification), name: UIDevice.orientationDidChangeNotification, object: nil)
}
@objc public func adjustFrameToCenter() {
@ -303,14 +296,8 @@ open class ImageScrollView: UIScrollView {
}
}
// MARK: - Actions
@objc func changeOrientationNotification() {
// A weird bug that frames are not update right after orientation changed. Need delay a little bit with async.
DispatchQueue.main.async {
open func resize() {
self.configureImageForSize(self.imageSize)
self.imageScrollViewDelegate?.imageScrollViewDidChangeOrientation(imageScrollView: self)
}
}
}

View File

@ -28,6 +28,13 @@ class ImageViewController: UIViewController {
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)
@ -46,9 +53,6 @@ class ImageViewController: UIViewController {
extension ImageViewController: ImageScrollViewDelegate {
func imageScrollViewDidChangeOrientation(imageScrollView: ImageScrollView) {
}
func imageScrollViewDidGestureSwipeUp(imageScrollView: ImageScrollView) {
dismiss(animated: true)
}

View File

@ -14,6 +14,7 @@ class RootSplitViewController: UISplitViewController {
var coordinator: SceneCoordinator!
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: { [weak self] context in
self?.coordinator.configureThreePanelMode(for: size)
})

View File

@ -819,6 +819,14 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
masterFeedViewController.present(addViewController, animated: true)
}
func showFullScreenImage(image: UIImage, transitioningDelegate: UIViewControllerTransitioningDelegate) {
let imageVC = UIStoryboard.main.instantiateController(ofType: ImageViewController.self)
imageVC.image = image
imageVC.modalPresentationStyle = .currentContext
imageVC.transitioningDelegate = transitioningDelegate
rootSplitViewController.present(imageVC, animated: true)
}
func toggleArticleExtractor() {
guard let article = currentArticle else {