Large Image VC: Show share sheet instead of downloading

This commit is contained in:
Shadowfacts 2019-06-14 17:10:17 -07:00
parent bd8e16cacb
commit 0abc28900c
Signed by: shadowfacts
GPG Key ID: 83FB3304046BADA4
2 changed files with 20 additions and 30 deletions

View File

@ -25,9 +25,9 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var topControlsView: UIView!
@IBOutlet weak var topControlsHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var downloadButton: UIButton!
@IBOutlet weak var downloadButtonTopConstraint: NSLayoutConstraint!
@IBOutlet weak var downloadButtonLeadingConstraint: NSLayoutConstraint!
@IBOutlet weak var shareButton: UIButton!
@IBOutlet weak var shareButtonTopConstraint: NSLayoutConstraint!
@IBOutlet weak var shareButtonLeadingConstraint: NSLayoutConstraint!
@IBOutlet weak var closeButton: UIButton!
@IBOutlet weak var closeButtonTopConstraint: NSLayoutConstraint!
@IBOutlet weak var closeButtonTrailingConstraint: NSLayoutConstraint!
@ -136,8 +136,8 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate {
// running on iPhone X style notched device
let notchWidth: CGFloat = 209
let earWidth = (view.bounds.width - notchWidth) / 2
let offset = (earWidth - downloadButton.bounds.width) / 2
downloadButtonLeadingConstraint.constant = offset
let offset = (earWidth - shareButton.bounds.width) / 2
shareButtonLeadingConstraint.constant = offset
closeButtonTrailingConstraint.constant = offset
}
}
@ -221,19 +221,10 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate {
dismiss(animated: true)
}
@IBAction func downloadPressed(_ sender: Any) {
@IBAction func sharePressed(_ sender: Any) {
guard let image = image else { return }
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAsset(from: image)
}, completionHandler: { success, error in
if success {
return
} else if let error = error {
print("Couldn't save photo: \(error)")
} else {
return
}
})
let activityVC = UIActivityViewController(activityItems: [image], applicationActivities: nil)
present(activityVC, animated: true)
}
}

View File

@ -1,10 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14810.11" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14766.13"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@ -16,15 +14,15 @@
<outlet property="closeButtonTopConstraint" destination="ImD-2H-0XK" id="DUe-b1-a2N"/>
<outlet property="closeButtonTrailingConstraint" destination="JFe-ig-3Ic" id="cWO-Rr-y3F"/>
<outlet property="descriptionLabel" destination="eo5-fc-RV8" id="vrW-RJ-y5k"/>
<outlet property="downloadButton" destination="vhp-0u-Q0S" id="JZS-K9-4w9"/>
<outlet property="downloadButtonLeadingConstraint" destination="MJx-2r-p0k" id="Dn5-Eg-Pid"/>
<outlet property="downloadButtonTopConstraint" destination="sgG-dC-xXP" id="Rjp-od-00F"/>
<outlet property="imageView" destination="qcn-1t-3sS" id="Q01-G2-y1c"/>
<outlet property="imageViewBottomConstraint" destination="3JF-Yo-5OR" id="1dh-W6-E8S"/>
<outlet property="imageViewLeadingConstraint" destination="bI3-V8-M70" id="nIe-xI-E9u"/>
<outlet property="imageViewTopConstraint" destination="tfL-hp-2I2" id="EDV-RO-pTe"/>
<outlet property="imageViewTrailingConstraint" destination="3bU-AI-KLl" id="IRq-jZ-u2s"/>
<outlet property="scrollView" destination="Skj-xq-AgQ" id="TFb-zF-m1b"/>
<outlet property="shareButton" destination="vhp-0u-Q0S" id="JZS-K9-4w9"/>
<outlet property="shareButtonLeadingConstraint" destination="MJx-2r-p0k" id="Dn5-Eg-Pid"/>
<outlet property="shareButtonTopConstraint" destination="sgG-dC-xXP" id="Rjp-od-00F"/>
<outlet property="topControlsHeightConstraint" destination="6XT-D6-8FS" id="mTB-LF-50H"/>
<outlet property="topControlsView" destination="kHo-B9-R7a" id="8sJ-xQ-7ix"/>
<outlet property="view" destination="BJw-5C-9nT" id="1C2-VA-mNf"/>
@ -61,9 +59,9 @@
<constraint firstAttribute="width" constant="20" id="zWx-jJ-dBj"/>
</constraints>
<color key="tintColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<state key="normal" image="Download"/>
<state key="normal" image="square.and.arrow.up" catalog="system"/>
<connections>
<action selector="downloadPressed:" destination="-1" eventType="touchUpInside" id="7Oz-zv-m2t"/>
<action selector="sharePressed:" destination="-1" eventType="touchUpInside" id="7Oz-zv-m2t"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="pnA-ne-k0v">
@ -72,8 +70,9 @@
<constraint firstAttribute="width" constant="20" id="eg0-hN-rda"/>
<constraint firstAttribute="height" constant="20" id="fmA-pI-8WB"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<color key="tintColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<state key="normal" image="Close"/>
<state key="normal" image="xmark" catalog="system"/>
<connections>
<action selector="closeButtonPressed:" destination="-1" eventType="touchUpInside" id="7o3-ET-EMo"/>
</connections>
@ -124,7 +123,7 @@
</view>
</objects>
<resources>
<image name="Close" width="209" height="209"/>
<image name="Download" width="284" height="284"/>
<image name="square.and.arrow.up" catalog="system" width="56" height="64"/>
<image name="xmark" catalog="system" width="64" height="56"/>
</resources>
</document>