From 866a378c8d6b9d78ea36f5b0711a4cec69ee9acb Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 30 Sep 2021 08:38:54 -0400 Subject: [PATCH] Add a scrollable and zoomable image view --- SilicaViewer/Base.lproj/Main.storyboard | 57 +++++++++++++++++++++---- SilicaViewer/ViewController.swift | 26 ++++++++--- 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/SilicaViewer/Base.lproj/Main.storyboard b/SilicaViewer/Base.lproj/Main.storyboard index 1008a81..8f2d5b4 100644 --- a/SilicaViewer/Base.lproj/Main.storyboard +++ b/SilicaViewer/Base.lproj/Main.storyboard @@ -354,18 +354,59 @@ Dk51bWJlciBvZiBMYXllcnM - + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/SilicaViewer/ViewController.swift b/SilicaViewer/ViewController.swift index 1f90ae9..5c16eb3 100644 --- a/SilicaViewer/ViewController.swift +++ b/SilicaViewer/ViewController.swift @@ -1,21 +1,35 @@ import Foundation import Cocoa +import Quartz class ViewController: NSViewController { @IBOutlet weak var imageView: NSImageView! + @IBOutlet weak var loadingField: NSTextField! + + override func viewDidLoad() { + + imageView.setContentCompressionResistancePriority( + .defaultLow, + for: .horizontal) + imageView.setContentCompressionResistancePriority( + .defaultLow, + for: .vertical) + + } + override func viewWillAppear() { let document = self.view.window?.windowController?.document as? Document DispatchQueue.main.async { - let image = document?.makeComposite() + guard let image = document?.makeComposite() else { + //self.loadingField.stringValue = "Failed to load." + return + } - //DispatchQueue.main.sync { - self.imageView.image = image - //} + self.imageView.image = image + //self.loadingField.isHidden = true } - - } override func prepare(for segue: NSStoryboardSegue, sender: Any?) {