Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close button toggle #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions ImageViewer/ImageViewerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ public final class ImageViewerController: UIViewController {
@IBOutlet fileprivate var scrollView: UIScrollView!
@IBOutlet fileprivate var imageView: UIImageView!
@IBOutlet fileprivate var activityIndicator: UIActivityIndicatorView!

@IBOutlet fileprivate var closeButton: UIButton!

fileprivate var transitionHandler: ImageViewerTransitioningHandler?
fileprivate let configuration: ImageViewerConfiguration?

Expand Down Expand Up @@ -65,10 +66,16 @@ private extension ImageViewerController {
}

func setupGestureRecognizers() {
let tapGestureRecognizer = UITapGestureRecognizer()
tapGestureRecognizer.numberOfTapsRequired = 2
tapGestureRecognizer.addTarget(self, action: #selector(imageViewDoubleTapped))
imageView.addGestureRecognizer(tapGestureRecognizer)
let doubleTapGestureRecognizer = UITapGestureRecognizer()
doubleTapGestureRecognizer.numberOfTapsRequired = 2
doubleTapGestureRecognizer.addTarget(self, action: #selector(imageViewDoubleTapped))
imageView.addGestureRecognizer(doubleTapGestureRecognizer)

let singleTapGestureRecognizer = UITapGestureRecognizer()
singleTapGestureRecognizer.numberOfTapsRequired = 1
singleTapGestureRecognizer.addTarget(self, action: #selector(imageViewSingleTapped))
singleTapGestureRecognizer.require(toFail: doubleTapGestureRecognizer)
imageView.addGestureRecognizer(singleTapGestureRecognizer)

let panGestureRecognizer = UIPanGestureRecognizer()
panGestureRecognizer.addTarget(self, action: #selector(imageViewPanned(_:)))
Expand Down Expand Up @@ -105,6 +112,19 @@ private extension ImageViewerController {
scrollView.setZoomScale(scrollView.maximumZoomScale, animated: true)
}
}

@objc func imageViewSingleTapped() {
let presenting = closeButton.isHidden
if presenting {
closeButton.isHidden = false
closeButton.alpha = 0.0
}
UIView.animate(withDuration: 0.25, animations: {
self.closeButton.alpha = presenting ? 1.0 : 0.0
}) { _ in
self.closeButton.isHidden = !presenting
}
}

@objc func imageViewPanned(_ recognizer: UIPanGestureRecognizer) {
guard transitionHandler != nil else { return }
Expand Down
4 changes: 3 additions & 1 deletion ImageViewer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.1.1</string>
<string>1.1.2</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand All @@ -24,6 +24,8 @@
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiresFullScreen</key>
<true/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UISupportedInterfaceOrientations</key>
Expand Down
5 changes: 3 additions & 2 deletions ImageViewer/Resources/ImageViewerController.xib
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ImageViewerController" customModule="SimpleImageViewer" customModuleProvider="target">
<connections>
<outlet property="activityIndicator" destination="oPl-2f-Knx" id="GOD-eG-o96"/>
<outlet property="closeButton" destination="Wsy-fe-raz" id="7Js-4z-1hL"/>
<outlet property="imageView" destination="rHA-5m-kkS" id="V86-k1-pPH"/>
<outlet property="scrollView" destination="cQD-2Q-pvo" id="M6k-QU-OVY"/>
<outlet property="view" destination="iN0-l3-epB" id="bEt-1B-b5l"/>
Expand Down
2 changes: 1 addition & 1 deletion SimpleImageViewer.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Pod::Spec.new do |s|
s.name = "SimpleImageViewer"
s.summary = "A snappy image viewer with zoom and interactive dismissal transition."
s.requires_arc = true
s.version = "1.1.1"
s.version = "1.1.2"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Lucas" => "[email protected]" }
s.homepage = "https://github.com/aFrogleap/SimpleImageViewer"
Expand Down
6 changes: 5 additions & 1 deletion SimpleImageViewer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = aFrogleap;
TargetAttributes = {
A02EE5D31EF1897D000EAB41 = {
Expand Down Expand Up @@ -449,13 +449,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -506,13 +508,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down