From 613c17bbeff63388ffa0475078ef22a64defc3d3 Mon Sep 17 00:00:00 2001 From: priteshrnandgaonkar Date: Tue, 27 Sep 2016 15:35:34 +0530 Subject: [PATCH 01/12] Made CardLayout public --- CardsStack.xcodeproj/project.pbxproj | 2 ++ CardsStack/CardLayout.swift | 24 ++++++++++++------------ CardsStack/CardStack.swift | 2 +- CardsStack/CardsManager.swift | 2 +- CardsStack/CardsStack.h | 2 +- CardsStackTests/CardsStackTests.swift | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/CardsStack.xcodeproj/project.pbxproj b/CardsStack.xcodeproj/project.pbxproj index c977de4..2bce94f 100644 --- a/CardsStack.xcodeproj/project.pbxproj +++ b/CardsStack.xcodeproj/project.pbxproj @@ -351,6 +351,7 @@ SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 3.0; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -371,6 +372,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_VERSION = 3.0; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; diff --git a/CardsStack/CardLayout.swift b/CardsStack/CardLayout.swift index 0bb508d..32c5ad9 100644 --- a/CardsStack/CardLayout.swift +++ b/CardsStack/CardLayout.swift @@ -2,27 +2,27 @@ // CardLayout.swift // DynamicStackOfCards // -// Created by housing on 9/16/16. +// Created by Pritesh Nandgaonkar on 9/16/16. // Copyright © 2016 pritesh. All rights reserved. // import Foundation import UIKit -protocol CardLayoutDelegate { +internal protocol CardLayoutDelegate { var fractionToMove: Float { get } var cardState: CardState { get } var configuration: Configuration { get } } -class CardLayout: UICollectionViewLayout { +public class CardLayout: UICollectionViewLayout { - var delegate: CardLayoutDelegate! - var contentHeight: CGFloat = 0.0 + internal var delegate: CardLayoutDelegate! + private var contentHeight: CGFloat = 0.0 - var cachedAttributes = [UICollectionViewLayoutAttributes]() + private var cachedAttributes = [UICollectionViewLayoutAttributes]() - override var collectionViewContentSize: CGSize { + public override var collectionViewContentSize: CGSize { let collection = collectionView! let width = collection.bounds.size.width let height = contentHeight @@ -30,7 +30,7 @@ class CardLayout: UICollectionViewLayout { return CGSize(width: width, height: height) } - override func prepare() { + override public func prepare() { cachedAttributes.removeAll() contentHeight = delegate.cardState == .Expanded ? 0.0 : CGFloat(delegate.configuration.collapsedHeight + delegate.fractionToMove) @@ -51,7 +51,7 @@ class CardLayout: UICollectionViewLayout { } } - override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { + override public func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { var layoutAttributes = [UICollectionViewLayoutAttributes]() @@ -64,15 +64,15 @@ class CardLayout: UICollectionViewLayout { return layoutAttributes } - override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { + override public func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { return true } - override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { + override public func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { return cachedAttributes[indexPath.item] } - func frameFor(index: Int, cardState: CardState, translation: Float) -> CGRect { + private func frameFor(index: Int, cardState: CardState, translation: Float) -> CGRect { var frame = CGRect(origin: CGPoint(x: CGFloat(delegate.configuration.leftSpacing), y:0), size: CGSize(width: UIScreen.main.bounds.width - CGFloat(delegate.configuration.leftSpacing + delegate.configuration.rightSpacing), height: CGFloat(delegate.configuration.cardHeight))) var frameOrigin = frame.origin switch cardState { diff --git a/CardsStack/CardStack.swift b/CardsStack/CardStack.swift index a56f3a6..c74bc9e 100644 --- a/CardsStack/CardStack.swift +++ b/CardsStack/CardStack.swift @@ -2,7 +2,7 @@ // CardStack.swift // DynamicStackOfCards // -// Created by housing on 9/24/16. +// Created by Pritesh Nandgaonkar on 9/24/16. // Copyright © 2016 pritesh. All rights reserved. // diff --git a/CardsStack/CardsManager.swift b/CardsStack/CardsManager.swift index b8ac9b6..100aa3a 100644 --- a/CardsStack/CardsManager.swift +++ b/CardsStack/CardsManager.swift @@ -2,7 +2,7 @@ // CardsManager.swift // DynamicStackOfCards // -// Created by housing on 9/24/16. +// Created by Pritesh Nandgaonkar on 9/24/16. // Copyright © 2016 pritesh. All rights reserved. // diff --git a/CardsStack/CardsStack.h b/CardsStack/CardsStack.h index b44e3d2..29a3865 100644 --- a/CardsStack/CardsStack.h +++ b/CardsStack/CardsStack.h @@ -2,7 +2,7 @@ // CardsStack.h // CardsStack // -// Created by housing on 9/24/16. +// Created by Pritesh Nandgaonkar on 9/24/16. // Copyright © 2016 Pritesh. All rights reserved. // diff --git a/CardsStackTests/CardsStackTests.swift b/CardsStackTests/CardsStackTests.swift index 1fb01f9..6bb19b0 100644 --- a/CardsStackTests/CardsStackTests.swift +++ b/CardsStackTests/CardsStackTests.swift @@ -2,7 +2,7 @@ // CardsStackTests.swift // CardsStackTests // -// Created by housing on 9/24/16. +// Created by Pritesh Nandgaonkar on 9/24/16. // Copyright © 2016 Pritesh. All rights reserved. // From b09579b6b377b7696235ad9d7b38f1a4c14c1fcc Mon Sep 17 00:00:00 2001 From: priteshrnandgaonkar Date: Tue, 27 Sep 2016 15:42:51 +0530 Subject: [PATCH 02/12] Added public headers in cardsstack --- CardsStack/CardsStack.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CardsStack/CardsStack.h b/CardsStack/CardsStack.h index 29a3865..a1c5dc7 100644 --- a/CardsStack/CardsStack.h +++ b/CardsStack/CardsStack.h @@ -15,5 +15,6 @@ FOUNDATION_EXPORT double CardsStackVersionNumber; FOUNDATION_EXPORT const unsigned char CardsStackVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import - +#import +#import From 1ad1d6ed0f45bfa30c3978bc921b30b9497a046d Mon Sep 17 00:00:00 2001 From: priteshrnandgaonkar Date: Tue, 27 Sep 2016 15:49:29 +0530 Subject: [PATCH 03/12] Solved the error while building --- CardsStack/CardsStack.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/CardsStack/CardsStack.h b/CardsStack/CardsStack.h index a1c5dc7..8c73bf4 100644 --- a/CardsStack/CardsStack.h +++ b/CardsStack/CardsStack.h @@ -15,6 +15,4 @@ FOUNDATION_EXPORT double CardsStackVersionNumber; FOUNDATION_EXPORT const unsigned char CardsStackVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import -#import -#import From defcf2036353d75d7f69ca3ca0243dedf175699e Mon Sep 17 00:00:00 2001 From: priteshrnandgaonkar Date: Tue, 27 Sep 2016 15:56:47 +0530 Subject: [PATCH 04/12] Made CardsManager internal --- CardsStack/CardStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CardsStack/CardStack.swift b/CardsStack/CardStack.swift index c74bc9e..01db9d9 100644 --- a/CardsStack/CardStack.swift +++ b/CardsStack/CardStack.swift @@ -53,7 +53,7 @@ public class CardStack { cardsManager.delegate = delegate } } - private var cardsManager = CardsManager() + internal var cardsManager = CardsManager() internal(set) var position: CardsPosition From f11e357c91f01f5f32e760f840e492ad81408987 Mon Sep 17 00:00:00 2001 From: priteshrnandgaonkar Date: Tue, 27 Sep 2016 16:16:39 +0530 Subject: [PATCH 05/12] added print statement for debugging --- CardsStack/CardLayout.swift | 14 ++++++++++---- CardsStack/CardsManager.swift | 7 ++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CardsStack/CardLayout.swift b/CardsStack/CardLayout.swift index 32c5ad9..baa4313 100644 --- a/CardsStack/CardLayout.swift +++ b/CardsStack/CardLayout.swift @@ -17,12 +17,12 @@ internal protocol CardLayoutDelegate { public class CardLayout: UICollectionViewLayout { - internal var delegate: CardLayoutDelegate! - private var contentHeight: CGFloat = 0.0 + internal var delegate: CardLayoutDelegate! + var contentHeight: CGFloat = 0.0 - private var cachedAttributes = [UICollectionViewLayoutAttributes]() + var cachedAttributes = [UICollectionViewLayoutAttributes]() - public override var collectionViewContentSize: CGSize { + public override var collectionViewContentSize: CGSize { let collection = collectionView! let width = collection.bounds.size.width let height = contentHeight @@ -31,6 +31,8 @@ public class CardLayout: UICollectionViewLayout { } override public func prepare() { + print("Prepare") + cachedAttributes.removeAll() contentHeight = delegate.cardState == .Expanded ? 0.0 : CGFloat(delegate.configuration.collapsedHeight + delegate.fractionToMove) @@ -52,6 +54,7 @@ public class CardLayout: UICollectionViewLayout { } override public func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { + print("CardManager Layout attributes") var layoutAttributes = [UICollectionViewLayoutAttributes]() @@ -65,10 +68,13 @@ public class CardLayout: UICollectionViewLayout { } override public func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { + print("SHOULD INVALIDATE") + return true } override public func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { + print("attributes for item at indexpath") return cachedAttributes[indexPath.item] } diff --git a/CardsStack/CardsManager.swift b/CardsStack/CardsManager.swift index 100aa3a..7e04f6b 100644 --- a/CardsStack/CardsManager.swift +++ b/CardsStack/CardsManager.swift @@ -15,7 +15,7 @@ internal enum CardState { case Collapsed } -internal class CardsManager: NSObject, CardLayoutDelegate { +class CardsManager: NSObject, CardLayoutDelegate { var fractionToMove:Float = 0 var cardState: CardState { @@ -99,9 +99,12 @@ internal class CardsManager: NSObject, CardLayoutDelegate { cardsView.addGestureRecognizer(tapGesture) panGesture.isEnabled = cardState == .Collapsed tapGesture.isEnabled = cardState == .Collapsed + print("CardManager Initialised") } func tappedCard(tapGesture: UITapGestureRecognizer) { + print("CardManager Tapped") + guard let cardsCollectionView = collectionView else { return } @@ -109,6 +112,8 @@ internal class CardsManager: NSObject, CardLayoutDelegate { } func pannedCard(panGesture: UIPanGestureRecognizer) { + print("CardManager Panned") + guard let collectionView = self.collectionView else { return } From c5e0d4c9a24cc1d48daa9cb323fd3ce86a537b5e Mon Sep 17 00:00:00 2001 From: priteshrnandgaonkar Date: Tue, 27 Sep 2016 16:35:09 +0530 Subject: [PATCH 06/12] Initialised layout in cardsmanager --- CardsStack/CardLayout.swift | 8 ++++++++ CardsStack/CardsManager.swift | 13 +++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CardsStack/CardLayout.swift b/CardsStack/CardLayout.swift index baa4313..241f500 100644 --- a/CardsStack/CardLayout.swift +++ b/CardsStack/CardLayout.swift @@ -22,6 +22,14 @@ public class CardLayout: UICollectionViewLayout { var cachedAttributes = [UICollectionViewLayoutAttributes]() + override init() { + super.init() + } + + required public init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + public override var collectionViewContentSize: CGSize { let collection = collectionView! let width = collection.bounds.size.width diff --git a/CardsStack/CardsManager.swift b/CardsStack/CardsManager.swift index 7e04f6b..80e8b01 100644 --- a/CardsStack/CardsManager.swift +++ b/CardsStack/CardsManager.swift @@ -89,10 +89,15 @@ class CardsManager: NSObject, CardLayoutDelegate { guard let cardsView = self.collectionView else { return } - cardsView.delegate = self - if let cardLayout = cardsView.collectionViewLayout as? CardLayout { - cardLayout.delegate = self - } +// cardsView.delegate = self +// if let cardLayout = cardsView.collectionViewLayout as? CardLayout { +// cardLayout.delegate = self +// } +// + let cardLayout = CardLayout() + cardLayout.delegate = self + cardsView.collectionViewLayout = cardLayout + panGesture = UIPanGestureRecognizer(target: self, action:#selector(self.pannedCard)) tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tappedCard)) cardsView.addGestureRecognizer(panGesture) From 15859965621f4d7a04debe90065e57e84277387a Mon Sep 17 00:00:00 2001 From: priteshrnandgaonkar Date: Tue, 27 Sep 2016 16:48:38 +0530 Subject: [PATCH 07/12] Assigned delegate to collectionview --- CardsStack/CardsManager.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CardsStack/CardsManager.swift b/CardsStack/CardsManager.swift index 80e8b01..4e85a6e 100644 --- a/CardsStack/CardsManager.swift +++ b/CardsStack/CardsManager.swift @@ -89,14 +89,11 @@ class CardsManager: NSObject, CardLayoutDelegate { guard let cardsView = self.collectionView else { return } -// cardsView.delegate = self -// if let cardLayout = cardsView.collectionViewLayout as? CardLayout { -// cardLayout.delegate = self -// } -// + let cardLayout = CardLayout() cardLayout.delegate = self cardsView.collectionViewLayout = cardLayout + cardsView.delegate = self panGesture = UIPanGestureRecognizer(target: self, action:#selector(self.pannedCard)) tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tappedCard)) @@ -231,18 +228,22 @@ class CardsManager: NSObject, CardLayoutDelegate { extension CardsManager: UICollectionViewDelegate { public func scrollViewDidScroll(_ scrollView: UIScrollView) { + print("CardManager SCROLLVIEWDIDSCROLL") - if scrollView.contentOffset.y < -10 { + if scrollView.contentOffset.y < 0 { panGesture.isEnabled = true scrollView.isScrollEnabled = false } } public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + print("CardManager DID SELECT AT ITEM AT INDEX PATH") + delegate?.cardsCollectionView?(collectionView, didSelectItemAt: indexPath) } public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { + print("CardManager WILLDISPLAY") delegate?.cardsCollectionView?(collectionView, willDisplay: cell, forItemAt: indexPath) } } From 4322f98a4e19bec41280687ee838b7df4cace51f Mon Sep 17 00:00:00 2001 From: priteshrnandgaonkar Date: Tue, 27 Sep 2016 17:17:10 +0530 Subject: [PATCH 08/12] Made cardlayout internal --- CardsStack/CardLayout.swift | 18 +++++++++--------- CardsStack/CardsManager.swift | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CardsStack/CardLayout.swift b/CardsStack/CardLayout.swift index 241f500..1c87954 100644 --- a/CardsStack/CardLayout.swift +++ b/CardsStack/CardLayout.swift @@ -15,9 +15,9 @@ internal protocol CardLayoutDelegate { var configuration: Configuration { get } } -public class CardLayout: UICollectionViewLayout { +class CardLayout: UICollectionViewLayout { - internal var delegate: CardLayoutDelegate! + var delegate: CardLayoutDelegate! var contentHeight: CGFloat = 0.0 var cachedAttributes = [UICollectionViewLayoutAttributes]() @@ -26,11 +26,11 @@ public class CardLayout: UICollectionViewLayout { super.init() } - required public init?(coder aDecoder: NSCoder) { + required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } - public override var collectionViewContentSize: CGSize { + override var collectionViewContentSize: CGSize { let collection = collectionView! let width = collection.bounds.size.width let height = contentHeight @@ -38,7 +38,7 @@ public class CardLayout: UICollectionViewLayout { return CGSize(width: width, height: height) } - override public func prepare() { + override func prepare() { print("Prepare") cachedAttributes.removeAll() @@ -61,7 +61,7 @@ public class CardLayout: UICollectionViewLayout { } } - override public func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { + override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { print("CardManager Layout attributes") var layoutAttributes = [UICollectionViewLayoutAttributes]() @@ -75,18 +75,18 @@ public class CardLayout: UICollectionViewLayout { return layoutAttributes } - override public func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { + override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { print("SHOULD INVALIDATE") return true } - override public func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { + override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { print("attributes for item at indexpath") return cachedAttributes[indexPath.item] } - private func frameFor(index: Int, cardState: CardState, translation: Float) -> CGRect { + func frameFor(index: Int, cardState: CardState, translation: Float) -> CGRect { var frame = CGRect(origin: CGPoint(x: CGFloat(delegate.configuration.leftSpacing), y:0), size: CGSize(width: UIScreen.main.bounds.width - CGFloat(delegate.configuration.leftSpacing + delegate.configuration.rightSpacing), height: CGFloat(delegate.configuration.cardHeight))) var frameOrigin = frame.origin switch cardState { diff --git a/CardsStack/CardsManager.swift b/CardsStack/CardsManager.swift index 4e85a6e..ad84465 100644 --- a/CardsStack/CardsManager.swift +++ b/CardsStack/CardsManager.swift @@ -89,10 +89,10 @@ class CardsManager: NSObject, CardLayoutDelegate { guard let cardsView = self.collectionView else { return } - let cardLayout = CardLayout() cardLayout.delegate = self cardsView.collectionViewLayout = cardLayout + cardsView.bounces = true cardsView.delegate = self panGesture = UIPanGestureRecognizer(target: self, action:#selector(self.pannedCard)) @@ -230,7 +230,7 @@ extension CardsManager: UICollectionViewDelegate { public func scrollViewDidScroll(_ scrollView: UIScrollView) { print("CardManager SCROLLVIEWDIDSCROLL") - if scrollView.contentOffset.y < 0 { + if scrollView.contentOffset.y < -10 { panGesture.isEnabled = true scrollView.isScrollEnabled = false } From 40e42cfccde7464b8e233aa25d7c1e2f930ad474 Mon Sep 17 00:00:00 2001 From: priteshrnandgaonkar Date: Tue, 27 Sep 2016 17:32:09 +0530 Subject: [PATCH 09/12] changed scrollview threshold to 0 --- CardsStack/CardsManager.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CardsStack/CardsManager.swift b/CardsStack/CardsManager.swift index ad84465..9a9c18f 100644 --- a/CardsStack/CardsManager.swift +++ b/CardsStack/CardsManager.swift @@ -179,7 +179,6 @@ class CardsManager: NSObject, CardLayoutDelegate { }, completion: { (finished) in self.triggerStateCallBack() }) - default: break } @@ -230,7 +229,7 @@ extension CardsManager: UICollectionViewDelegate { public func scrollViewDidScroll(_ scrollView: UIScrollView) { print("CardManager SCROLLVIEWDIDSCROLL") - if scrollView.contentOffset.y < -10 { + if scrollView.contentOffset.y < 0 { panGesture.isEnabled = true scrollView.isScrollEnabled = false } From e450d0e9d5b9cc99a992533c9f0b4d6e2f137834 Mon Sep 17 00:00:00 2001 From: priteshrnandgaonkar Date: Tue, 27 Sep 2016 21:53:17 +0530 Subject: [PATCH 10/12] Enable vertical bouncing --- CardsStack/CardsManager.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/CardsStack/CardsManager.swift b/CardsStack/CardsManager.swift index 9a9c18f..16d3900 100644 --- a/CardsStack/CardsManager.swift +++ b/CardsStack/CardsManager.swift @@ -93,6 +93,7 @@ class CardsManager: NSObject, CardLayoutDelegate { cardLayout.delegate = self cardsView.collectionViewLayout = cardLayout cardsView.bounces = true + cardsView.alwaysBounceVertical = true cardsView.delegate = self panGesture = UIPanGestureRecognizer(target: self, action:#selector(self.pannedCard)) From e3bf74862aa661db9544a454c279f3ea907db2c3 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Thu, 29 Sep 2016 14:45:11 +0530 Subject: [PATCH 11/12] Added documentation and removed print statements --- CardsStack/CardLayout.swift | 6 ---- CardsStack/CardStack.swift | 64 ++++++++++++++++++++++++++++++++--- CardsStack/CardsManager.swift | 7 ---- 3 files changed, 59 insertions(+), 18 deletions(-) diff --git a/CardsStack/CardLayout.swift b/CardsStack/CardLayout.swift index 1c87954..cb14b63 100644 --- a/CardsStack/CardLayout.swift +++ b/CardsStack/CardLayout.swift @@ -39,8 +39,6 @@ class CardLayout: UICollectionViewLayout { } override func prepare() { - print("Prepare") - cachedAttributes.removeAll() contentHeight = delegate.cardState == .Expanded ? 0.0 : CGFloat(delegate.configuration.collapsedHeight + delegate.fractionToMove) @@ -62,7 +60,6 @@ class CardLayout: UICollectionViewLayout { } override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { - print("CardManager Layout attributes") var layoutAttributes = [UICollectionViewLayoutAttributes]() @@ -76,13 +73,10 @@ class CardLayout: UICollectionViewLayout { } override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { - print("SHOULD INVALIDATE") - return true } override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { - print("attributes for item at indexpath") return cachedAttributes[indexPath.item] } diff --git a/CardsStack/CardStack.swift b/CardsStack/CardStack.swift index 01db9d9..6c5fac5 100644 --- a/CardsStack/CardStack.swift +++ b/CardsStack/CardStack.swift @@ -9,22 +9,50 @@ import Foundation import UIKit -@objc public enum CardsPosition: Int { - case Collapsed - case Expanded -} - +/// Struct for the UI information related to cards. public struct Configuration { + + /// Offset(distance between the top of the consecutive cards) between the cards while the cards are in collapsed state public let cardOffset: Float + + /// Height of the collection view when the cards are in collapsed state public let collapsedHeight:Float + + /// Height of the collection view when the cards are in expanded state public let expandedHeight:Float + + /// Height of the cards public let cardHeight: Float + + /// The minimum threshold required for the cards to be dragged down when the cards are in expanded state public let downwardThreshold: Float + + /// The minimum threshold required for the cards to be dragged up when the cards are in collapsed state public let upwardThreshold: Float + + /// Vertical Spacing between the cards while the cards are in expanded state public let verticalSpacing: Float + + /// Leading space for the cards public let leftSpacing: Float + + /// Trailing space for the cards public let rightSpacing: Float + + /// init + /// + /// - parameter cardOffset: Offset(distance between the top of the consecutive cards) between the cards while the cards are in collapsed state + /// - parameter collapsedHeight: Height of the collection view when the cards are in collapsed state + /// - parameter expandedHeight: Height of the collection view when the cards are in expanded state + /// - parameter cardHeight: Height of the cards + /// - parameter downwardThreshold: The minimum threshold required for the cards to be dragged down when the cards are in expanded state. Its an optional field. Default value is 20 + /// - parameter upwardThreshold: The minimum threshold required for the cards to be dragged up when the cards are in collapsed state. Its an optional field. Default value is 20 + /// - parameter leftSpacing: Leading space for the cards. Its not a required field, default value is 8 + /// - parameter rightSpacing: Trailing space for the cards. Optional field, default value is 8 + /// - parameter verticalSpacing: Leading space for the cards. Optional field, default value is 8 + /// + /// - returns: Configuration public init(cardOffset: Float, collapsedHeight: Float, expandedHeight: Float, cardHeight: Float, downwardThreshold: Float = 20, upwardThreshold: Float = 20, leftSpacing: Float = 8.0, rightSpacing: Float = 8.0, verticalSpacing: Float = 8.0) { self.cardOffset = cardOffset self.collapsedHeight = collapsedHeight @@ -38,6 +66,16 @@ public struct Configuration { } } +/// Enum for decribing the state of the cards +@objc public enum CardsPosition: Int { + /// Case when the cards are collapsed + case Collapsed + + /// Case when the cards are expanded + case Expanded +} + +/// Delegate to get hooks to interaction over cards @objc public protocol CardsManagerDelegate { @objc optional func cardsPositionChangedTo(position: CardsPosition) @@ -46,6 +84,7 @@ public struct Configuration { @objc optional func cardsCollectionView(_ cardsCollectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) } +/// Class for initialising stack of cards public class CardStack { public weak var delegate: CardsManagerDelegate? = nil { @@ -57,12 +96,24 @@ public class CardStack { internal(set) var position: CardsPosition + /// init + /// uses config = Configuration(cardOffset: 40, collapsedHeight: 200, expandedHeight: 500, cardHeight: 200, downwardThreshold: 20, upwardThreshold: 20) in + /// init(cardsState: .Collapsed, configuration: config, collectionView: nil, collectionViewHeight: nil) + /// - returns: CardStack public convenience init() { let configuration = Configuration(cardOffset: 40, collapsedHeight: 200, expandedHeight: 500, cardHeight: 200, downwardThreshold: 20, upwardThreshold: 20) self.init(cardsState: .Collapsed, configuration: configuration, collectionView: nil, collectionViewHeight: nil) } + /// init + /// + /// - parameter cardsState: Initial state of the cards + /// - parameter configuration: Instance of the Configuration, which holds the UI related information + /// - parameter collectionView: UICollectionView + /// - parameter collectionViewHeight: NSLayoutConstraint, height constraint of the collectionview + /// + /// - returns: CardStack public init(cardsState: CardsPosition, configuration: Configuration, collectionView: UICollectionView?, collectionViewHeight: NSLayoutConstraint?) { position = cardsState @@ -70,6 +121,9 @@ public class CardStack { cardsManager.cardsDelegate = self } + /// changeCardsPosition(to position: CardsPosition) + /// This function can be called on CardStack to change the state of cardsStack. It can be used to programmatically change the states of the cards stack + /// - parameter position: CardsPosition public func changeCardsPosition(to position: CardsPosition) { cardsManager.updateView(with: position) } diff --git a/CardsStack/CardsManager.swift b/CardsStack/CardsManager.swift index 16d3900..d24faaf 100644 --- a/CardsStack/CardsManager.swift +++ b/CardsStack/CardsManager.swift @@ -102,12 +102,9 @@ class CardsManager: NSObject, CardLayoutDelegate { cardsView.addGestureRecognizer(tapGesture) panGesture.isEnabled = cardState == .Collapsed tapGesture.isEnabled = cardState == .Collapsed - print("CardManager Initialised") } func tappedCard(tapGesture: UITapGestureRecognizer) { - print("CardManager Tapped") - guard let cardsCollectionView = collectionView else { return } @@ -115,7 +112,6 @@ class CardsManager: NSObject, CardLayoutDelegate { } func pannedCard(panGesture: UIPanGestureRecognizer) { - print("CardManager Panned") guard let collectionView = self.collectionView else { return @@ -228,7 +224,6 @@ class CardsManager: NSObject, CardLayoutDelegate { extension CardsManager: UICollectionViewDelegate { public func scrollViewDidScroll(_ scrollView: UIScrollView) { - print("CardManager SCROLLVIEWDIDSCROLL") if scrollView.contentOffset.y < 0 { panGesture.isEnabled = true @@ -237,13 +232,11 @@ extension CardsManager: UICollectionViewDelegate { } public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - print("CardManager DID SELECT AT ITEM AT INDEX PATH") delegate?.cardsCollectionView?(collectionView, didSelectItemAt: indexPath) } public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { - print("CardManager WILLDISPLAY") delegate?.cardsCollectionView?(collectionView, willDisplay: cell, forItemAt: indexPath) } } From 44a4c408eb463b203e421edf37095c8f1b873439 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Thu, 29 Sep 2016 14:56:03 +0530 Subject: [PATCH 12/12] Updated Readme with Carthage compatibility icon --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ba37c4f..07ab72a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ -# CardStack +# CardStack [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) -CardStack converts your `UICollectionView` to an awesome stack of cards + +CardStack converts your `UICollectionView` to an awesome stack of cards using custom `UICollectionViewLayout` ## What is CardStack? 💫 ✨💥⭐️ @@ -91,13 +92,13 @@ With this delegate you can get the hooks to specific events } ``` -For listening to thiscall backs add assign a delegate to `CardsStack` +For listening to this call backs assign a delegate to `CardsStack` ``` swift cardsStack.delegate = self ``` -The last two functions leads are the same as the delegate function for collection view. +The last two functions are the same as the delegate function for collection view. The first function gives the hook to the `CardStacks` position change @@ -127,7 +128,7 @@ public func changeCardsPosition(to position: CardsPosition) { You can checkout the example and play around with it to get hang of the API's ## TODO -- [ ] Carthage Support +- [x] Carthage Support - [ ] CocoaPods Support - [ ] SwiftPM Support - [ ] Watch, TvOS Targets