Skip to content

Commit

Permalink
Merge branch 'release/1.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Boldt committed Jan 21, 2017
2 parents 9d22dec + 74691b6 commit f41f884
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.2.2 (2017-01-21)
- Removed .none as backgroundStyle and replaced it with .dimmed and an associated value: .dimmed(alpha: CGFloat)
- Code cleanup

## 1.2.1 (2017-01-11)
- Fixed issue with background tap dismissal options

Expand Down
4 changes: 3 additions & 1 deletion Example/Jelly.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

/* Begin PBXFileReference section */
152009C91E26C6EA00537CD5 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = CHANGELOG.md; path = ../CHANGELOG.md; sourceTree = "<group>"; };
154175841E337E4F00503A99 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
154509481DF6084B0096C822 /* Jelly_Tests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Jelly_Tests-Bridging-Header.h"; sourceTree = "<group>"; };
154509491DF6084C0096C822 /* JellyAnimatorSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JellyAnimatorSpec.swift; sourceTree = "<group>"; };
155B7B841DE1E5820093DF2A /* CustomNavController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomNavController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -90,6 +91,7 @@
607FACC71AFB9204008FA782 = {
isa = PBXGroup;
children = (
154175841E337E4F00503A99 /* README.md */,
152009C91E26C6EA00537CD5 /* CHANGELOG.md */,
15B1CF991DEB7299003B4107 /* Github */,
607FACF51AFB993E008FA782 /* Podspec Metadata */,
Expand Down Expand Up @@ -225,7 +227,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = CocoaPods;
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Example/Jelly/ExampleDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct ExampleDataProvider {
let slideOverPresentation = JellySlideInPresentation(dismissCurve: .linear,
presentationCurve: .linear,
cornerRadius: 0,
backgroundStyle: .dimmed,
backgroundStyle: .dimmed(alpha: 0.5),
jellyness: .none,
duration: .normal,
directionShow: .left,
Expand Down
2 changes: 1 addition & 1 deletion Jelly.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Pod::Spec.new do |s|
s.name = 'Jelly'
s.version = '1.2.1'
s.version = '1.2.2'
s.summary = 'Jelly provides custom view controller animations with just a few lines of code'

s.description = <<-DESC
Expand Down
3 changes: 1 addition & 2 deletions Jelly/Classes/JellyConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public struct JellyConstants {
}

public enum BackgroundStyle {
case dimmed
case dimmed(alpha: CGFloat)
case blur(effectStyle: UIBlurEffectStyle)
case none
}

/// Will the ViewController be shown or dismissed?
Expand Down
4 changes: 2 additions & 2 deletions Jelly/Classes/JellyFadeInPresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public struct JellyFadeInPresentation: JellyPresentation, AlignablePresentation,
public var dismissCurve: JellyConstants.JellyCurve = .linear
public var presentationCurve: JellyConstants.JellyCurve = .linear
public var cornerRadius: Double = 0.0
public var backgroundStyle: JellyConstants.BackgroundStyle = .dimmed
public var backgroundStyle: JellyConstants.BackgroundStyle = .dimmed(alpha: 0.5)
public var duration : JellyConstants.Duration = .normal // Duration the ViewController needs to kick in
public var widthForViewController: JellyConstants.Size = .halfscreen
public var heightForViewController: JellyConstants.Size = .halfscreen
Expand All @@ -26,7 +26,7 @@ public struct JellyFadeInPresentation: JellyPresentation, AlignablePresentation,
public init(dismissCurve: JellyConstants.JellyCurve = .linear,
presentationCurve: JellyConstants.JellyCurve = .linear,
cornerRadius: Double = 0.0,
backgroundStyle: JellyConstants.BackgroundStyle = .dimmed,
backgroundStyle: JellyConstants.BackgroundStyle = .dimmed(alpha: 0.5),
duration: JellyConstants.Duration = .normal,
widthForViewController: JellyConstants.Size = .fullscreen,
heightForViewController: JellyConstants.Size = .fullscreen,
Expand Down
9 changes: 4 additions & 5 deletions Jelly/Classes/JellyFadeInPresentationAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ final class JellyFadeInPresentationAnimator: NSObject {
}

extension JellyFadeInPresentationAnimator : UIViewControllerAnimatedTransitioning {

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return presentation.duration.rawValue
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {

let key: UITransitionContextViewControllerKey = getViewControllerKeyForPresentationType(type: self.presentationType)
let key = getViewControllerKeyForPresentationType(type: self.presentationType)
let isPresentation = key == .to
let controllerToAnimate = transitionContext.viewController(forKey: key)!

Expand All @@ -51,17 +50,17 @@ extension JellyFadeInPresentationAnimator : UIViewControllerAnimatedTransitionin
animations: {
controllerToAnimate.view.alpha = CGFloat(finalAlpha)
}, completion:{ finished in
transitionContext.completeTransition(finished)
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})

}

private func getViewControllerKeyForPresentationType(type: JellyConstants.PresentationType) -> UITransitionContextViewControllerKey {
switch type {
case .show:
return UITransitionContextViewControllerKey.to
return .to
case .dismiss:
return UITransitionContextViewControllerKey.from
return .from
}
}
}
57 changes: 36 additions & 21 deletions Jelly/Classes/JellyPresentationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import UIKit


/// A JellyPresentationControllers tells UIKit what exactly to do with the View that should be presented
/// It also react to Transtion states etc.
/// We basically use this controller to setup dimmingView, blurView, positioning the presented ViewController etc.
/// It also reacts to transtion state changes etc.
/// We use this controller to setup dimmingView, blurView, positioning the presented ViewController etc.
class JellyPresentationController : UIPresentationController {

fileprivate var presentation: JellyPresentation
fileprivate var dimmingView: UIView! // The PresentationController manages the dimmingView
fileprivate var blurView: UIVisualEffectView!
fileprivate var dimmingView: UIView?
fileprivate var blurView: UIVisualEffectView?

init(presentedViewController: UIViewController, presentingViewController: UIViewController?, presentation: JellyPresentation) {

Expand All @@ -23,23 +23,24 @@ class JellyPresentationController : UIPresentationController {
presentedViewController.view.layer.masksToBounds = true
presentedViewController.view.roundCorners(corners: self.presentation.corners, radius: presentation.cornerRadius)

self.setupDimmingView()
self.setupBlurView()
self.setupBackgroundViews(forBackGroundStyle: presentation.backgroundStyle)
}

/// Presentation and Dismissal stuff
override func presentationTransitionWillBegin() {
switch self.presentation.backgroundStyle {
case .blur(let effectStyle):
animateBlurView(effectStyle: effectStyle)
case .dimmed:
case .dimmed(_):
animateDimmingView()
case .none:
()
}
}

private func animateBlurView(effectStyle: UIBlurEffectStyle) {
guard let blurView = self.blurView else {
return
}

containerView?.insertSubview(blurView, at: 0)
NSLayoutConstraint.activate(
NSLayoutConstraint.constraints(withVisualFormat: "V:|[blurView]|",
Expand All @@ -55,12 +56,16 @@ class JellyPresentationController : UIPresentationController {

UIView.animate(withDuration: presentation.duration.rawValue, animations: {
let effect = UIBlurEffect(style: effectStyle)
self.blurView.effect = effect
blurView.effect = effect

})
}

private func animateDimmingView() {
guard let dimmingView = self.dimmingView else {
return
}

containerView?.insertSubview(dimmingView, at: 0)
NSLayoutConstraint.activate(
NSLayoutConstraint.constraints(withVisualFormat: "V:|[dimmingView]|",
Expand All @@ -75,22 +80,22 @@ class JellyPresentationController : UIPresentationController {
}

coordinator.animate(alongsideTransition: { _ in
self.dimmingView.alpha = 1.0
dimmingView.alpha = 1.0
})
}

override func dismissalTransitionWillBegin() {
guard let coordinator = presentedViewController.transitionCoordinator else {
dimmingView.alpha = 0.0
dimmingView?.alpha = 0.0
return
}

coordinator.animate(alongsideTransition: { _ in
self.dimmingView.alpha = 0.0
self.dimmingView?.alpha = 0.0
})

UIView.animate(withDuration: presentation.duration.rawValue, animations: {
self.blurView.effect = nil
self.blurView?.effect = nil
})
}

Expand Down Expand Up @@ -261,21 +266,31 @@ class JellyPresentationController : UIPresentationController {


fileprivate extension JellyPresentationController {
fileprivate func setupBackgroundViews(forBackGroundStyle backGroundStyle: JellyConstants.BackgroundStyle) {
switch backGroundStyle {
case .dimmed(let alpha):
self.setupDimmingView(withAlpha: alpha)
case .blur(let effectStyle):
self.setupBlurView()
}
}

// We are not setting the Blur style over here because we need to animate it later
func setupBlurView () {
blurView = UIVisualEffectView()
blurView.translatesAutoresizingMaskIntoConstraints = false
blurView?.translatesAutoresizingMaskIntoConstraints = false
let recognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap(recognizer:)))
blurView.addGestureRecognizer(recognizer)
blurView?.addGestureRecognizer(recognizer)
}

func setupDimmingView() {
func setupDimmingView(withAlpha alpha: CGFloat = 0.5) {
dimmingView = UIView()
dimmingView.translatesAutoresizingMaskIntoConstraints = false
dimmingView.alpha = 0.0
dimmingView.backgroundColor = UIColor(white: 0.0, alpha: 0.5)
dimmingView?.translatesAutoresizingMaskIntoConstraints = false
dimmingView?.alpha = 0.0
dimmingView?.backgroundColor = UIColor(white: 0.0, alpha: alpha)

let recognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap(recognizer:)))
dimmingView.addGestureRecognizer(recognizer)
dimmingView?.addGestureRecognizer(recognizer)
}

dynamic func handleTap(recognizer: UITapGestureRecognizer) {
Expand Down
4 changes: 2 additions & 2 deletions Jelly/Classes/JellyShiftInPresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct JellyShiftInPresentation: JellyPresentation {
public var dismissCurve: JellyConstants.JellyCurve = .linear
public var presentationCurve: JellyConstants.JellyCurve = .linear
public var cornerRadius: Double = 0.0
public var backgroundStyle: JellyConstants.BackgroundStyle = .none
public var backgroundStyle: JellyConstants.BackgroundStyle = .dimmed(alpha:0.5)
public var jellyness: JellyConstants.Jellyness = .none
public var duration : JellyConstants.Duration = .medium // Duration the ViewController needs to kick in
public var isTapBackgroundToDismissEnabled: Bool = true
Expand All @@ -23,7 +23,7 @@ public struct JellyShiftInPresentation: JellyPresentation {
public init(dismissCurve: JellyConstants.JellyCurve = .linear,
presentationCurve: JellyConstants.JellyCurve = .linear,
cornerRadius: Double = 0.0,
backgroundStyle: JellyConstants.BackgroundStyle = .dimmed,
backgroundStyle: JellyConstants.BackgroundStyle = .dimmed(alpha: 0.5),
jellyness: JellyConstants.Jellyness = .none,
duration: JellyConstants.Duration = .normal,
direction: JellyConstants.Direction = .bottom,
Expand Down
14 changes: 7 additions & 7 deletions Jelly/Classes/JellyShiftInPresentationAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ extension JellyShiftInPresentationAnimator : UIViewControllerAnimatedTransitioni
// Refactor this please .... 😡
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {

let presentedKey: UITransitionContextViewControllerKey = getPresentedViewControllerKeyForPresentationType(type: self.presentationType)
let underlyingKey: UITransitionContextViewControllerKey = getUnderlyingViewControllerKeyForPresentationType(type: self.presentationType)
let presentedKey = getPresentedViewControllerKeyForPresentationType(type: self.presentationType)
let underlyingKey = getUnderlyingViewControllerKeyForPresentationType(type: self.presentationType)

let isPresentation = (presentedKey == .to) // Are we presenting or dismissing
let presentedViewController = transitionContext.viewController(forKey: presentedKey)! // ViewController that will be presented and removed on dismissal
Expand Down Expand Up @@ -87,7 +87,7 @@ extension JellyShiftInPresentationAnimator : UIViewControllerAnimatedTransitioni
underlyingViewController.view.frame = finalFrameForUnderlying

}, completion:{ finished in
transitionContext.completeTransition(finished)
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})

}
Expand Down Expand Up @@ -117,18 +117,18 @@ extension JellyShiftInPresentationAnimator : UIViewControllerAnimatedTransitioni
private func getPresentedViewControllerKeyForPresentationType(type: JellyConstants.PresentationType) -> UITransitionContextViewControllerKey {
switch type {
case .show:
return UITransitionContextViewControllerKey.to
return .to
case .dismiss:
return UITransitionContextViewControllerKey.from
return .from
}
}

private func getUnderlyingViewControllerKeyForPresentationType(type: JellyConstants.PresentationType) -> UITransitionContextViewControllerKey {
switch type {
case .show:
return UITransitionContextViewControllerKey.from
return .from
case .dismiss:
return UITransitionContextViewControllerKey.to
return .to
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Jelly/Classes/JellySlideInPresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public struct JellySlideInPresentation: JellyPresentation, AlignablePresentation
public var dismissCurve: JellyConstants.JellyCurve = .linear
public var presentationCurve: JellyConstants.JellyCurve = .linear
public var cornerRadius: Double = 0.0
public var backgroundStyle: JellyConstants.BackgroundStyle = .none
public var backgroundStyle: JellyConstants.BackgroundStyle = .dimmed(alpha: 0.5)
public var jellyness: JellyConstants.Jellyness
public var duration : JellyConstants.Duration = .normal // Duration the ViewController needs to kick in
public var widthForViewController: JellyConstants.Size = .halfscreen
Expand All @@ -29,7 +29,7 @@ public struct JellySlideInPresentation: JellyPresentation, AlignablePresentation
public init(dismissCurve: JellyConstants.JellyCurve = .linear,
presentationCurve: JellyConstants.JellyCurve = .linear,
cornerRadius: Double = 0.0,
backgroundStyle: JellyConstants.BackgroundStyle = .dimmed,
backgroundStyle: JellyConstants.BackgroundStyle = .dimmed(alpha: 0.5),
jellyness: JellyConstants.Jellyness = .none,
duration: JellyConstants.Duration = .normal,
directionShow: JellyConstants.Direction = .top,
Expand Down
8 changes: 4 additions & 4 deletions Jelly/Classes/JellySlideInPresentationAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension JellySlideInPresentationAnimator : UIViewControllerAnimatedTransitioni

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {

let key: UITransitionContextViewControllerKey = getViewControllerKeyForPresentationType(type: self.presentationType)
let key = getViewControllerKeyForPresentationType(type: self.presentationType)
let isPresentation = key == .to
let controllerToAnimate = transitionContext.viewController(forKey: key)!

Expand Down Expand Up @@ -61,7 +61,7 @@ extension JellySlideInPresentationAnimator : UIViewControllerAnimatedTransitioni
animations: {
controllerToAnimate.view.frame = finalFrame
}, completion:{ finished in
transitionContext.completeTransition(finished)
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})

}
Expand Down Expand Up @@ -91,9 +91,9 @@ extension JellySlideInPresentationAnimator : UIViewControllerAnimatedTransitioni
private func getViewControllerKeyForPresentationType(type: JellyConstants.PresentationType) -> UITransitionContextViewControllerKey {
switch type {
case .show:
return UITransitionContextViewControllerKey.to
return .to
case .dismiss:
return UITransitionContextViewControllerKey.from
return .from
}
}
}
4 changes: 2 additions & 2 deletions Jelly/Classes/UIView+Jelly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import Foundation
import UIKit

extension UIView {
public func roundCorners(corners: UIRectCorner = [.topLeft, .topRight, .bottomLeft, .bottomRight] , radius: Double = 0.0) {
public func roundCorners(corners: UIRectCorner = .allCorners, radius: Double = 0.0) {
self.layer.masksToBounds = true
let maskPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width:radius,height:radius))
let maskPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width:radius, height:radius))
let shape = CAShapeLayer()
shape.path = maskPath.cgPath
self.layer.mask = shape
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ Check outh the interfaces of each class to learn more about them.
* normal = 0.35
* fast = 0.2
* reallyFast = 0.1
* **backgroundStyle:** JellyConstants.BackgroundStyle (default: dimmed)
* dimmed
* blur(effectStyle)
* none
* **backgroundStyle:** JellyConstants.BackgroundStyle (default: .dimmed(0.5))
* dimmed(alpha: CGFloat)
* blur(effectStyle: UIBlurEffectStyle)
* if you want a transparent background use .dimmed(alpha:0.0)
* **cornerRadius:** Double (default: 0)
* **corners:** UIRectCorner (default: .allCorners)
* define which corners the radius should be applied to
Expand Down

0 comments on commit f41f884

Please sign in to comment.