From a91edbe098385124af835f6c23cd51dc3e71fc12 Mon Sep 17 00:00:00 2001 From: Daniel Lozano Date: Mon, 17 Oct 2016 19:44:28 -0500 Subject: [PATCH 1/2] fixed dismissOnSwipe bug --- Presentr.xcodeproj/project.pbxproj | 17 ++++++++++++ Presentr/Presentr.swift | 6 ++--- Presentr/PresentrController.swift | 26 +++++++++++++------ .../PresentrExample/ViewController.swift | 2 +- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Presentr.xcodeproj/project.pbxproj b/Presentr.xcodeproj/project.pbxproj index 4e56b43..4613c42 100644 --- a/Presentr.xcodeproj/project.pbxproj +++ b/Presentr.xcodeproj/project.pbxproj @@ -185,6 +185,7 @@ 0680CC2B1CE3EFA900CBAE4F /* Frameworks */, 0680CC2C1CE3EFA900CBAE4F /* Headers */, 0680CC2D1CE3EFA900CBAE4F /* Resources */, + 06A15EA31DB5A73F005DD3DA /* ShellScript */, ); buildRules = ( ); @@ -271,6 +272,22 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 06A15EA31DB5A73F005DD3DA /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 0680CC2A1CE3EFA900CBAE4F /* Sources */ = { isa = PBXSourcesBuildPhase; diff --git a/Presentr/Presentr.swift b/Presentr/Presentr.swift index 634f315..afbd995 100644 --- a/Presentr/Presentr.swift +++ b/Presentr/Presentr.swift @@ -60,8 +60,8 @@ public class Presentr: NSObject { /// Should the presented controller dismiss on background tap. Default is true. public var dismissOnTap = true - /// Should the presented controller dismiss on Swipe. Default is true. - public var dismissOnSwipe = true + /// Should the presented controller dismiss on Swipe inside the presented view controller. Default is false. + public var dismissOnSwipe = false /// Should the presented controller use animation when dismiss on background tap. Default is true. public var dismissAnimated = true @@ -78,7 +78,7 @@ public class Presentr: NSObject { /// The type of blur to be applied to the background. Ignored if blurBackground is set to false. Default is Dark. public var blurStyle: UIBlurEffectStyle = .dark - /// How the presented view controller should respond in response to keyboard presentation. + /// How the presented view controller should respond to keyboard presentation. public var keyboardTranslationType: KeyboardTranslationType = .none // MARK: Private Helper Properties diff --git a/Presentr/PresentrController.swift b/Presentr/PresentrController.swift index 55f184d..965345d 100644 --- a/Presentr/PresentrController.swift +++ b/Presentr/PresentrController.swift @@ -93,20 +93,27 @@ class PresentrController: UIPresentationController, UIAdaptivePresentationContro } else { removeCornerRadiusFromPresentedView() } - + + if dismissOnSwipe { + setupDismissOnSwipe() + } + if shouldObserveKeyboard { registerKeyboardObserver() } + } // MARK: Setup - fileprivate func setupChromeView(_ backgroundColor: UIColor, backgroundOpacity: Float, blurBackground: Bool, blurStyle: UIBlurEffectStyle) { - let tap = UITapGestureRecognizer(target: self, action: #selector(chromeViewTapped)) - chromeView.addGestureRecognizer(tap) - + private func setupDismissOnSwipe() { let swipe = UIPanGestureRecognizer(target: self, action: #selector(presentingViewSwipe)) presentedViewController.view.addGestureRecognizer(swipe) + } + + private func setupChromeView(_ backgroundColor: UIColor, backgroundOpacity: Float, blurBackground: Bool, blurStyle: UIBlurEffectStyle) { + let tap = UITapGestureRecognizer(target: self, action: #selector(chromeViewTapped)) + chromeView.addGestureRecognizer(tap) if blurBackground { let blurEffectView = UIVisualEffectView(effect: UIBlurEffect(style: blurStyle)) @@ -118,12 +125,12 @@ class PresentrController: UIPresentationController, UIAdaptivePresentationContro } } - fileprivate func addCornerRadiusToPresentedView() { + private func addCornerRadiusToPresentedView() { presentedViewController.view.layer.cornerRadius = 4 presentedViewController.view.layer.masksToBounds = true } - fileprivate func removeCornerRadiusFromPresentedView() { + private func removeCornerRadiusFromPresentedView() { presentedViewController.view.layer.cornerRadius = 0 } @@ -157,14 +164,17 @@ class PresentrController: UIPresentationController, UIAdaptivePresentationContro let gestureState: (UIGestureRecognizerState) -> Bool = { return gesture.state == $0 && self.dismissOnSwipe } + guard (conformingPresentedController?.presentrShouldDismiss?(keyboardShowing: keyboardIsShowing) ?? true) else { return } + if gestureState(.began) { translationStart = gesture.location(in: presentedViewController.view) + }else if gestureState(.changed) { let amount = gesture.translation(in: presentedViewController.view) - if amount.y < 0 {return} + if amount.y < 0 { return } let translation = swipeElasticityFactor * 2 let center = presentedViewController.view.center diff --git a/PresentrExample/PresentrExample/ViewController.swift b/PresentrExample/PresentrExample/ViewController.swift index 0ee6ed8..a542114 100644 --- a/PresentrExample/PresentrExample/ViewController.swift +++ b/PresentrExample/PresentrExample/ViewController.swift @@ -137,7 +137,7 @@ class ViewController: UIViewController { @IBAction func keyboardTranslation(_ sender: AnyObject) { presenter.presentationType = .popup - presenter.keyboardTranslationType = .moveUp + presenter.keyboardTranslationType = .compress customPresentViewController(presenter, viewController: popupViewController, animated: true, completion: nil) } From abe28adbf7befefac152668c3c43a42bf093370c Mon Sep 17 00:00:00 2001 From: Daniel Lozano Date: Mon, 17 Oct 2016 19:46:20 -0500 Subject: [PATCH 2/2] Fixed version numbers --- Presentr.podspec | 4 ++-- Presentr/Info.plist | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Presentr.podspec b/Presentr.podspec index aa58f17..b2b2976 100644 --- a/Presentr.podspec +++ b/Presentr.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Presentr" - s.version = "1.0.1" + s.version = "1.0.2" s.summary = "A simple Swift wrapper for typical custom view controller presentations." s.description = <<-DESC A micro framework created in Swift. Simplifies creating custom view controller presentations. Specially the typical ones we use which are a popup, an alert, or a any non-full-screen modal. Abstracts having to deal with custom presentation controllers and transitioning delegates @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.author = { "Daniel Lozano" => "dan@danielozano.com" } s.social_media_url = "http://twitter.com/danlozanov" s.platform = :ios, "9.0" - s.source = { :git => "https://github.com/icalialabs/Presentr.git", :tag => "1.0.1" } + s.source = { :git => "https://github.com/icalialabs/Presentr.git", :tag => "1.0.2" } s.source_files = "Presentr/**/*.{swift}" s.resources = "Presentr/**/*.{xib,ttf}" end diff --git a/Presentr/Info.plist b/Presentr/Info.plist index b07122f..9a87e23 100644 --- a/Presentr/Info.plist +++ b/Presentr/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0.1 + 1.0.2 CFBundleSignature ???? CFBundleVersion