Skip to content
This repository was archived by the owner on Oct 18, 2022. It is now read-only.

Commit cfc825f

Browse files
authored
Merge pull request #11 from netguru/develop
Release 1.1.0
2 parents d6cc7b0 + 2ab8bfb commit cfc825f

8 files changed

+122
-20
lines changed

CarLensCollectionViewLayout.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "CarLensCollectionViewLayout"
4-
s.version = "1.0.0"
4+
s.version = "1.1.0"
55
s.summary = "An easy to use Collection View Layout for card-like animation."
66

77
s.homepage = "https://github.com/netguru/CarLensCollectionViewLayout"

CarLensCollectionViewLayout.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
9518383821E4F31F00BEA6EB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9518382421E4F08300BEA6EB /* Assets.xcassets */; };
1818
9518383921E4F32800BEA6EB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9518382921E4F08300BEA6EB /* AppDelegate.swift */; };
1919
9518383C21E4FFCA00BEA6EB /* CollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9518383B21E4FFCA00BEA6EB /* CollectionViewCell.swift */; };
20+
9518384821E623E800BEA6EB /* CarLensCollectionViewLayoutOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9518384721E623E800BEA6EB /* CarLensCollectionViewLayoutOptions.swift */; };
2021
955E4FD421CBFB2800B4C3BB /* CarLensCollectionViewLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 955E4FD221CBFB2800B4C3BB /* CarLensCollectionViewLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
2122
958D17C021D66DF00067BED6 /* CarLensCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 958D17BF21D66DF00067BED6 /* CarLensCollectionViewCell.swift */; };
2223
/* End PBXBuildFile section */
@@ -56,6 +57,7 @@
5657
9518382921E4F08300BEA6EB /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
5758
9518382A21E4F08300BEA6EB /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5859
9518383B21E4FFCA00BEA6EB /* CollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewCell.swift; sourceTree = "<group>"; };
60+
9518384721E623E800BEA6EB /* CarLensCollectionViewLayoutOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CarLensCollectionViewLayoutOptions.swift; sourceTree = "<group>"; };
5961
955E4FCF21CBFB2800B4C3BB /* CarLensCollectionViewLayout.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CarLensCollectionViewLayout.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6062
955E4FD221CBFB2800B4C3BB /* CarLensCollectionViewLayout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CarLensCollectionViewLayout.h; sourceTree = "<group>"; };
6163
955E4FD321CBFB2800B4C3BB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -126,6 +128,7 @@
126128
children = (
127129
955E4FD221CBFB2800B4C3BB /* CarLensCollectionViewLayout.h */,
128130
9505725D21D4D8FB009EA422 /* CarLensCollectionViewLayout.swift */,
131+
9518384721E623E800BEA6EB /* CarLensCollectionViewLayoutOptions.swift */,
129132
958D17BF21D66DF00067BED6 /* CarLensCollectionViewCell.swift */,
130133
9505725F21D4D922009EA422 /* CarLensLayoutAttributes.swift */,
131134
955E4FD321CBFB2800B4C3BB /* Info.plist */,
@@ -256,6 +259,7 @@
256259
isa = PBXSourcesBuildPhase;
257260
buildActionMask = 2147483647;
258261
files = (
262+
9518384821E623E800BEA6EB /* CarLensCollectionViewLayoutOptions.swift in Sources */,
259263
9505725E21D4D8FB009EA422 /* CarLensCollectionViewLayout.swift in Sources */,
260264
958D17C021D66DF00067BED6 /* CarLensCollectionViewCell.swift in Sources */,
261265
9505726021D4D922009EA422 /* CarLensLayoutAttributes.swift in Sources */,

CarLensCollectionViewLayout/CarLensCollectionViewCell.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ open class CarLensCollectionViewCell: UICollectionViewCell {
1919
/// The bottom view of the cell.
2020
public var cardView: UIView!
2121

22-
private let topViewHeight: CGFloat = UIScreen.main.bounds.height > 568 ? 200 : 170
22+
/// The height of the top view.
23+
public var topViewHeight: CGFloat!
2324

2425
/// Configuration of the cell. Must be called on a start.
2526
///
2627
/// - Parameters:
2728
/// - topView: The upper view of the cell.
2829
/// - cardView: The bottom view of the cell.
29-
open func configure(topView: UIView, cardView: UIView) {
30+
/// - topViewHeight: An optional parameter to specify the custom height of the top view. The default value is `170` or `200` depending on a device's size.
31+
open func configure(topView: UIView, cardView: UIView, topViewHeight: CGFloat = UIScreen.main.bounds.height > 568 ? 200 : 170) {
32+
self.topViewHeight = topViewHeight
3033
self.topView = topView
3134
self.cardView = cardView
3235
setupView()

CarLensCollectionViewLayout/CarLensCollectionViewLayout.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
#import <UIKit/UIKit.h>
99

10-
//! Project version number for CarlensCollectionViewLayout.
11-
FOUNDATION_EXPORT double CarlensCollectionViewLayoutVersionNumber;
10+
//! Project version number for CarLensCollectionViewLayout.
11+
FOUNDATION_EXPORT double CarLensCollectionViewLayoutVersionNumber;
1212

13-
//! Project version string for CarlensCollectionViewLayout.
14-
FOUNDATION_EXPORT const unsigned char CarlensCollectionViewLayoutVersionString[];
13+
//! Project version string for CarLensCollectionViewLayout.
14+
FOUNDATION_EXPORT const unsigned char CarLensCollectionViewLayoutVersionString[];
1515

16-
// In this header, you should import all the public headers of your framework using statements like #import <CarlensCollectionViewLayout/PublicHeader.h>
16+
// In this header, you should import all the public headers of your framework using statements like #import <CarLensCollectionViewLayout/PublicHeader.h>
1717

1818

CarLensCollectionViewLayout/CarLensCollectionViewLayout.swift

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public final class CarLensCollectionViewLayout: UICollectionViewFlowLayout {
1111

1212
private var firstSetupDone = false
1313

14+
private let options: CarLensCollectionViewLayoutOptions
15+
1416
/// SeeAlso: UICollectionViewFlowLayout
1517
public override func prepare() {
1618
super.prepare()
@@ -19,14 +21,31 @@ public final class CarLensCollectionViewLayout: UICollectionViewFlowLayout {
1921
firstSetupDone = true
2022
}
2123

24+
25+
/// The initialization of the CarLensCollectionViewLayout.
26+
///
27+
/// - Parameters:
28+
/// - options: An optional additional configuration of the layout.
29+
public init(options: CarLensCollectionViewLayoutOptions = CarLensCollectionViewLayoutOptions()) {
30+
self.options = options
31+
super.init()
32+
}
33+
34+
public required init?(coder aDecoder: NSCoder) {
35+
self.options = CarLensCollectionViewLayoutOptions()
36+
super.init(coder: aDecoder)
37+
}
38+
2239
private func setup() {
2340
guard let collectionView = collectionView else { return }
2441
scrollDirection = .horizontal
25-
minimumLineSpacing = 20
26-
itemSize = CGSize(width: collectionView.bounds.width - 80, height: collectionView.bounds.height)
27-
let inset = (collectionView.bounds.width - itemSize.width) / 2
28-
collectionView.contentInset = .init(top: 0, left: inset, bottom: 0, right: inset)
29-
collectionView.decelerationRate = UIScrollView.DecelerationRate.fast
42+
minimumLineSpacing = options.minimumSpacing
43+
itemSize = options.itemSize ?? CGSize(width: collectionView.bounds.width - 60, height: collectionView.bounds.height)
44+
let sidesInset = (collectionView.bounds.width - itemSize.width) / 2
45+
let topAndBottomInset = (collectionView.bounds.height - itemSize.height) / 2
46+
collectionView.contentInset = .init(top: topAndBottomInset, left: sidesInset, bottom: topAndBottomInset, right: sidesInset)
47+
collectionView.decelerationRate = options.decelerationRate
48+
collectionView.showsHorizontalScrollIndicator = options.shouldShowScrollIndicator
3049
}
3150

3251
/// SeeAlso: UICollectionViewFlowLayout
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// CarLensCollectionViewLayoutOptions.swift
3+
// CarLensCollectionViewLayout
4+
//
5+
// Copyright © 2019 Netguru. All rights reserved.
6+
//
7+
8+
import UIKit
9+
10+
/// The optional configuration of CarLensCollectionViewLayout. Use this if you need to customize `CarLensCollectionViewLayout`.
11+
public struct CarLensCollectionViewLayoutOptions {
12+
13+
/// A minimum spacing between cells.
14+
let minimumSpacing: CGFloat
15+
16+
/// A deceleration for a scroll view.
17+
let decelerationRate: UIScrollView.DecelerationRate
18+
19+
/// A value indicating whether collection view should have a scroll indicator.
20+
let shouldShowScrollIndicator: Bool
21+
22+
/// The size to use for cells.
23+
let itemSize: CGSize?
24+
25+
/// The initialization of the optional layout configuration.
26+
/// You can initialize it with any of the parameters available. Others will be configured automatically.
27+
///
28+
/// - Parameters:
29+
/// - minimumSpacing: A minimum spacing between cells. The default value is `20`.
30+
/// - decelerationRate: A deceleration for a scroll view. The default value is `.fast`.
31+
/// - shouldShowScrollIndicator: A value indicating whether collection view should have a scroll indicator. The default value is `false`.
32+
/// - itemSize: The size to use for cells. The default height is equal to a collection view height. The width is equal to the `collection view width - 60`.
33+
public init(minimumSpacing: CGFloat = 20, decelerationRate: UIScrollView.DecelerationRate = UIScrollView.DecelerationRate.fast, shouldShowScrollIndicator: Bool = false, itemSize: CGSize? = nil) {
34+
self.minimumSpacing = minimumSpacing
35+
self.decelerationRate = decelerationRate
36+
self.shouldShowScrollIndicator = shouldShowScrollIndicator
37+
self.itemSize = itemSize
38+
}
39+
40+
}

CarLensCollectionViewLayout/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0</string>
18+
<string>1.1.0</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
</dict>

README.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
![](https://img.shields.io/badge/carthage-compatible-green.svg)
66
![](https://app.bitrise.io/app/23a07b63b3f55f97/status.svg?token=Rt_2gKUavbR8LQ7PVuTbYg&branch=master)
77

8-
An easy to use Collection View Layout for card-like animation 🎉
8+
An easy-to-use Collection View Layout for card-like animation 🎉
99

1010
<p align="center">
1111
<img src="https://user-images.githubusercontent.com/18245585/50694808-2b795e80-103b-11e9-839d-f2d8dc533bb4.gif" width="250">
@@ -20,9 +20,11 @@ An easy to use Collection View Layout for card-like animation 🎉
2020

2121
## Usage
2222

23+
### Basic Usage
24+
2325
The two main steps are needed for the configuration of *CarLensCollectionViewLayout*:
2426

25-
### Step 1
27+
#### Step 1
2628
Assign `CarLensCollectionViewLayout` to yours collection view layout:
2729
```swift
2830
collectionView.collectionViewLayout = CarLensCollectionViewLayout()
@@ -32,7 +34,7 @@ or initialize your collection view with `CarLensCollectionViewLayout`:
3234
UICollectionView(frame: .zero, collectionViewLayout: CarLensCollectionViewLayout())
3335
```
3436

35-
### Step 2
37+
#### Step 2
3638
Subsclass `CarLensCollectionViewCell` and call `configure(topView: UIView, cardView: UIView)` right on the start!
3739
```swift
3840
class CollectionViewCell: CarLensCollectionViewCell {
@@ -42,7 +44,41 @@ class CollectionViewCell: CarLensCollectionViewCell {
4244
}
4345
}
4446
```
45-
The sample implementation is available in [Demo](CarLensCollectionViewDemo) project.
47+
The sample implementation is available in [Demo](CarLensCollectionViewLayoutDemo) project.
48+
49+
### Customization
50+
51+
#### Layout
52+
You can also initialize `CarLensCollectionViewLayout` with a `CarLensCollectionViewLayoutOptions` object by passing any of the parameters available. Others will be configured automatically.
53+
54+
**Parameters:**
55+
56+
`minimumSpacing` - A minimum spacing between cells.
57+
58+
`decelerationRate` - A deceleration for a scroll view.
59+
60+
`shouldShowScrollIndicator` - A value indicating whether collection view should have a scroll indicator.
61+
62+
`itemSize` - The size to use for cells.
63+
64+
Example:
65+
```swift
66+
let options = CarLensCollectionViewLayoutOptions(minimumSpacing: 40)
67+
collectionView.collectionViewLayout = CarLensCollectionViewLayout(options: options)
68+
```
69+
70+
#### Cell
71+
While subsclassing `CarLensCollectionViewCell` you can call `configure(...)` with an additional parameter `topViewHeight`. The card view height will be calculated based on this value.
72+
73+
Example:
74+
```swift
75+
class CollectionViewCell: CarLensCollectionViewCell {
76+
override init(frame: CGRect) {
77+
super.init(frame: frame)
78+
configure(topView: upperView, cardView: bottomView, topViewHeight: 300)
79+
}
80+
}
81+
```
4682

4783
## Installation
4884

@@ -52,15 +88,15 @@ If you're using [CocoaPods](http://cocoapods.org), add the following dependency
5288

5389
```none
5490
use_frameworks!
55-
pod 'CarLensCollectionViewLayout', '~> 1.0.0'
91+
pod 'CarLensCollectionViewLayout', '~> 1.1.0'
5692
```
5793

5894
### Carthage
5995

6096
If you're using [Carthage](https://github.com/Carthage/Carthage), add the following dependency to your `Cartfile`:
6197

6298
```none
63-
github "netguru/CarLensCollectionViewLayout" ~> 1.0.0
99+
github "netguru/CarLensCollectionViewLayout" ~> 1.1.0
64100
```
65101

66102
## About

0 commit comments

Comments
 (0)