1
Fork 0

Add a scrollable and zoomable image view

This commit is contained in:
Joshua Goins 2021-09-30 08:38:54 -04:00
parent e1d869ffdc
commit 866a378c8d
2 changed files with 69 additions and 14 deletions

View file

@ -354,18 +354,59 @@ Dk51bWJlciBvZiBMYXllcnM
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/> <rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ipM-NH-wUM"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="O48-im-AhA">
<rect key="frame" x="198" y="127" width="84" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Please wait..." id="Kok-lN-RvC">
<font key="font" metaFont="system"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<scrollView borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" allowsMagnification="YES" minMagnification="1" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uGT-cg-c7j">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/> <rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/> <clipView key="contentView" drawsBackground="NO" id="Roy-oU-Le6">
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="chN-IE-x52"/> <rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<connections> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<segue destination="qzy-T7-vHd" kind="show" identifier="showTimelapse" id="x99-kP-axt"/> <subviews>
</connections> <view id="hNn-Aa-CKW">
<rect key="frame" x="0.0" y="0.0" width="485" height="269"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="y0M-Hn-T88">
<rect key="frame" x="0.0" y="0.0" width="485" height="269"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="tHf-wP-P5i"/>
</imageView> </imageView>
</subviews> </subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="y0M-Hn-T88" secondAttribute="trailing" id="Sdu-6P-R1c"/>
<constraint firstItem="y0M-Hn-T88" firstAttribute="top" secondItem="hNn-Aa-CKW" secondAttribute="top" id="ady-cn-4PV"/>
<constraint firstItem="y0M-Hn-T88" firstAttribute="leading" secondItem="hNn-Aa-CKW" secondAttribute="leading" id="cLP-tg-Yig"/>
<constraint firstAttribute="bottom" secondItem="y0M-Hn-T88" secondAttribute="bottom" id="y9b-EB-Ayo"/>
</constraints>
</view>
</subviews>
</clipView>
<scroller key="horizontalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="C44-w5-6zH">
<rect key="frame" x="0.0" y="254" width="480" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="YYV-ak-nuJ">
<rect key="frame" x="464" y="0.0" width="16" height="270"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
</subviews>
<constraints>
<constraint firstItem="uGT-cg-c7j" firstAttribute="centerY" secondItem="O48-im-AhA" secondAttribute="centerY" id="1Ok-fG-D0h"/>
<constraint firstItem="O48-im-AhA" firstAttribute="centerY" secondItem="ERx-hH-rdd" secondAttribute="centerY" id="37m-I2-CEB"/>
<constraint firstItem="uGT-cg-c7j" firstAttribute="leading" secondItem="ERx-hH-rdd" secondAttribute="leading" id="CU5-lz-k01"/>
<constraint firstItem="uGT-cg-c7j" firstAttribute="top" secondItem="ERx-hH-rdd" secondAttribute="top" id="kVI-CM-NkV"/>
<constraint firstItem="O48-im-AhA" firstAttribute="centerX" secondItem="ERx-hH-rdd" secondAttribute="centerX" id="m1F-HX-aB9"/>
<constraint firstItem="uGT-cg-c7j" firstAttribute="centerX" secondItem="O48-im-AhA" secondAttribute="centerX" id="naX-FM-6aN"/>
</constraints>
</view> </view>
<connections> <connections>
<outlet property="imageView" destination="ipM-NH-wUM" id="RT5-09-Hwj"/> <outlet property="imageView" destination="y0M-Hn-T88" id="Wch-Vz-0ui"/>
<segue destination="wda-Mt-beD" kind="sheet" identifier="showInfo" id="obo-Yt-yny"/> <segue destination="wda-Mt-beD" kind="sheet" identifier="showInfo" id="obo-Yt-yny"/>
</connections> </connections>
</viewController> </viewController>

View file

@ -1,21 +1,35 @@
import Foundation import Foundation
import Cocoa import Cocoa
import Quartz
class ViewController: NSViewController { class ViewController: NSViewController {
@IBOutlet weak var imageView: NSImageView! @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() { override func viewWillAppear() {
let document = self.view.window?.windowController?.document as? Document let document = self.view.window?.windowController?.document as? Document
DispatchQueue.main.async { DispatchQueue.main.async {
let image = document?.makeComposite() guard let image = document?.makeComposite() else {
//self.loadingField.stringValue = "Failed to load."
//DispatchQueue.main.sync { return
self.imageView.image = image
//}
} }
self.imageView.image = image
//self.loadingField.isHidden = true
}
} }
override func prepare(for segue: NSStoryboardSegue, sender: Any?) { override func prepare(for segue: NSStoryboardSegue, sender: Any?) {