From d849a612c529ff0bc1d4374f4aebc66a6e35d83a Mon Sep 17 00:00:00 2001 From: gwangbeom Date: Wed, 16 Jan 2019 12:15:33 +0900 Subject: [PATCH] 0.2.5 --- Configs/Sheet.plist | 2 +- README.md | 4 +-- Sheet.podspec | 2 +- Sources/Animator/SheetFadeAnimator.swift | 9 ++++-- .../SheetNavigationController.swift | 9 ++++-- Sources/Manager/SheetManager.swift | 2 ++ Sources/Manager/SheetOptions.swift | 31 +++++++++++++++++++ 7 files changed, 51 insertions(+), 8 deletions(-) diff --git a/Configs/Sheet.plist b/Configs/Sheet.plist index 5f10cf0..7337b91 100644 --- a/Configs/Sheet.plist +++ b/Configs/Sheet.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.2.4 + 0.2.5 CFBundleSignature ???? CFBundleVersion diff --git a/README.md b/README.md index 7b1d52f..2a61e96 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,12 @@ ### CocoaPods ```bash -pod 'Sheet', '~> 0.2.4' +pod 'Sheet', '~> 0.2.5' ``` ### Carthage ```bash -github "ParkGwangBeom/Sheet" ~> 0.2.4 +github "ParkGwangBeom/Sheet" ~> 0.2.5 ``` ### Manually diff --git a/Sheet.podspec b/Sheet.podspec index 1c7860f..0b280ee 100644 --- a/Sheet.podspec +++ b/Sheet.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Sheet" - s.version = "0.2.4" + s.version = "0.2.5" s.swift_version = '4.0' s.summary = "Navigationable Action Sheet" s.description = "💦 Navigable custom action sheet like Flipboard" diff --git a/Sources/Animator/SheetFadeAnimator.swift b/Sources/Animator/SheetFadeAnimator.swift index a959040..68bc1f8 100644 --- a/Sources/Animator/SheetFadeAnimator.swift +++ b/Sources/Animator/SheetFadeAnimator.swift @@ -17,6 +17,11 @@ class SheetFadeAnimator: NSObject, UIViewControllerAnimatedTransitioning { private var options: SheetOptions { return SheetManager.shared.options } + + private var animationOption: SheetAnimationOption { + return SheetManager.shared.animationOption + } + private var toTopMargin: CGFloat = 0 private var fromTopMargin: CGFloat = 0 @@ -27,7 +32,7 @@ class SheetFadeAnimator: NSObject, UIViewControllerAnimatedTransitioning { } func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { - return 0.4 + return animationOption.pushAnimationItem.duration } func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { @@ -56,7 +61,7 @@ class SheetFadeAnimator: NSObject, UIViewControllerAnimatedTransitioning { onReady?() - UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.75, initialSpringVelocity: 1, options: [.curveEaseOut], animations: { + UIView.animate(withDuration: animationOption.pushAnimationItem.duration, delay: 0, usingSpringWithDamping: animationOption.pushAnimationItem.springDumping, initialSpringVelocity: animationOption.pushAnimationItem.initialSpringVelocity, options: animationOption.pushAnimationItem.options, animations: { fromContainer?.alpha = 0 fromContainer?.contentOffset.y += diff diff --git a/Sources/Controller/SheetNavigationController.swift b/Sources/Controller/SheetNavigationController.swift index d3188b6..c00fe33 100644 --- a/Sources/Controller/SheetNavigationController.swift +++ b/Sources/Controller/SheetNavigationController.swift @@ -13,6 +13,10 @@ public class SheetNavigationController: UINavigationController { private var options: SheetOptions { return SheetManager.shared.options } + + private var animationItem: AnimationItem { + return SheetManager.shared.animationOption.presentAnimationItem + } /// Height constraints of the Sheet Toolbar public var toolBarHeightConstraint: NSLayoutConstraint? @@ -55,11 +59,12 @@ public class SheetNavigationController: UINavigationController { rootViewController?.collectionView?.transform = CGAffineTransform(translationX: 0, y: visibleHeight + options.sheetToolBarHeight) sheetToolBarContainerView?.transform = CGAffineTransform(translationX: 0, y: SheetManager.shared.options.sheetToolBarHeight + UIEdgeInsets.safeAreaInsets.bottom) - UIView.animate(withDuration: 0.45, delay: 0, usingSpringWithDamping: 0.75, initialSpringVelocity: 1, options: [.curveEaseOut], animations: { + + UIView.animate(withDuration: animationItem.duration, delay: 0, usingSpringWithDamping: animationItem.springDumping, initialSpringVelocity: animationItem.initialSpringVelocity, options: animationItem.options, animations: { rootViewController?.collectionView?.transform = .identity }, completion: nil) - UIView.animate(withDuration: 0.2) { + UIView.animate(withDuration: 0.3) { self.backgroundView?.alpha = 1 self.sheetToolBarContainerView?.transform = .identity } diff --git a/Sources/Manager/SheetManager.swift b/Sources/Manager/SheetManager.swift index aa26364..ed976a9 100644 --- a/Sources/Manager/SheetManager.swift +++ b/Sources/Manager/SheetManager.swift @@ -13,4 +13,6 @@ import UIKit public static let shared = SheetManager() public var options = SheetOptions() + + public var animationOption = SheetAnimationOption() } diff --git a/Sources/Manager/SheetOptions.swift b/Sources/Manager/SheetOptions.swift index fdd7ed0..84039eb 100644 --- a/Sources/Manager/SheetOptions.swift +++ b/Sources/Manager/SheetOptions.swift @@ -77,3 +77,34 @@ public struct SheetOptions { /// sheet background color public var sheetBackgroundColor: UIColor = .white } + +public struct SheetAnimationOption { + + public init() { } + + public var presentAnimationItem = AnimationItem() + + public var pushAnimationItem = AnimationItem(duration: 0.5, springDumping: 0.8, initialSpringVelocity: 1) +} + +public struct AnimationItem { + + public init(duration: TimeInterval = 0.6, springDumping: CGFloat = 0.8, initialSpringVelocity: CGFloat = 1, options: UIView.AnimationOptions = [.curveEaseOut]) { + self.duration = duration + self.springDumping = springDumping + self.initialSpringVelocity = initialSpringVelocity + self.options = options + } + + /// sheet present animation duration. Defaults to 0.6 + public var duration: TimeInterval = 0.6 + + /// sheet present animation spring dumping value. Defaults to 0.8 + public var springDumping: CGFloat = 0.8 + + /// sheet present animation initial spring velocity. Defaults to 1 + public var initialSpringVelocity: CGFloat = 1 + + /// sheet present animation options. + public var options: UIView.AnimationOptions = [.curveEaseOut] +}