Skip to content
This repository was archived by the owner on Jun 17, 2023. It is now read-only.

Commit 2c390b4

Browse files
authored
Update README.md
1 parent d120b9c commit 2c390b4

File tree

1 file changed

+53
-14
lines changed

1 file changed

+53
-14
lines changed

README.md

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
77
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)
88

9-
## Preview
9+
## Layout Designer
10+
<img width="600" src="https://amir.app/git/layout_designer_preview.gif"></img>
1011

11-
<p float="left">
12-
<img width="200" src="https://amir.app/git/flowlayout_preview.gif"></img>
13-
<img width="200" src="https://amir.app/git/gallery_preview.gif"></img>
14-
<img width="200" src="https://amir.app/git/cards_preview.gif"></img>
15-
</p>
1612

1713
### SnapshotTransformView
1814

@@ -50,10 +46,21 @@
5046
<img width="100" src="https://amir.app/git/shapes_preview/stack_vortex.gif"></img>
5147
</p>
5248

49+
## Custom implementation
50+
51+
<p float="left">
52+
<img width="100" src="https://amir.app/git/flowlayout_preview.gif"></img>
53+
<img width="100" src="https://amir.app/git/gallery_preview.gif"></img>
54+
<img width="100" src="https://amir.app/git/cards_preview.gif"></img>
55+
</p>
56+
57+
5358
## About
54-
This is a custom `UICollectionViewLayout` that gives you the ability to apply transforms easily on the cells
55-
by conforming your cell class to `TransformableView` protocol you will get a `progress` value and you can use it to apply any changes on your cell view.
56-
See [How to use](https://github.com/amirdew/CollectionViewPagingLayout#how-to-use) part for more details.
59+
CollectionViewPagingLayout is a simple but powerful tool for making complex layouts for your UICollectionView.
60+
The implementation is very simple there is custom `UICollectionViewLayout` that gives you the ability to apply transforms on the cells.
61+
No inheritance or anything like that.
62+
See [How to use](https://github.com/amirdew/CollectionViewPagingLayout#how-to-use) part for more details.
63+
5764

5865
## Installation
5966
CollectionViewPagingLayout doesn't contain any external dependencies.
@@ -97,6 +104,19 @@ File > Swift Packages > Add Package Dependency
97104
Just add all the files under `Lib` directory to your project
98105

99106
## How to use
107+
108+
### Using Layout Designer
109+
110+
There is a macOS app to make it even easier for you to make your own custom layout.
111+
It allows you to tweak many options and see the result in real time.
112+
- Clone the repository then build and run the mac app.
113+
- Tweak options and design your layout.
114+
- Copy the code from the right panel and paste it on Xcode, make sure to choose "ViewController" if you need the full implementation.
115+
- Don't forget to [install](https://github.com/amirdew/CollectionViewPagingLayout#installation) the libray
116+
117+
118+
### Manually
119+
100120
- Make sure you imported the library
101121
```swift
102122
import CollectionViewPagingLayout
@@ -110,9 +130,10 @@ collectionView.collectionViewLayout = layout
110130
collectionView.isPagingEnabled = true // enabling paging effect
111131
```
112132

113-
- Now you just need to conform your `UICollectionViewCell` class to `TransformableView` and start implementing your custom transforms.
133+
- Now you just need to conform your `UICollectionViewCell` class to `TransformableView` and start implementing your custom transforms. By conforming your cell class to `TransformableView` protocol you will get a `progress` value and you can use it to apply any changes on your cell view.
114134

115-
*Note:* you can use [Prepared Transformable Protocols](#prepared-transformable-protocols) instead of `TransformableView` if you don't want a custom effect!
135+
136+
*Note:* you can use [Prepared Transformable Protocols](#prepared-transformable-protocols) instead of `TransformableView` if you want to use prepared effects!
116137

117138
```swift
118139
extension MyCollectionViewCell: TransformableView {
@@ -209,26 +230,44 @@ to find the public function(s) for each tansformable check the protocol definiti
209230

210231
## Other features
211232

212-
You can control the current page by following public functions of `CollectionViewPagingLayout`:
233+
### Control current page
234+
235+
You can control the current page by the following functions of `CollectionViewPagingLayout`:
213236
- `func setCurrentPage(_ page: Int, animated: Bool = true)`
214237
- `func goToNextPage(animated: Bool = true)`
215238
- `func goToPreviousPage(animated: Bool = true)`
216239

217240
these are safe wrappers for setting `ContentOffset` of `UICollectionview`
218-
you can also get current page by a public variable `CollectionViewPagingLayout.currentPage` or listen to the changes by setting `CollectionViewPagingLayout.delegate`:
219-
241+
you can also get current page by a public variable `CollectionViewPagingLayout.currentPage` or listen to changes by using `CollectionViewPagingLayout.delegate`:
220242
```swift
221243
public protocol CollectionViewPagingLayoutDelegate: class {
222244
func onCurrentPageChanged(layout: CollectionViewPagingLayout, currentPage: Int)
223245
}
224246
```
225247

248+
### Handle touches
249+
250+
There is built-in solution for handling tap gestues on the views
251+
- Implement `TransformableView.selectableView` and pass the view that you would like to handle tap gestues for (by default this is the first subview of your `UICollectionViewCell.contentView`)
252+
- Call `CollectionViewPagingLayout.configureTapOnCollectionView()` after setting the layout for you collection view
253+
- Set the delegate for layout (`CollectionViewPagingLayout.delegate`)
254+
- Use didSelectItemAt function `func collectionViewPagingLayout(_ layout: CollectionViewPagingLayout, didSelectItemAt indexPath: IndexPath)`
255+
226256

227257
## Limitations
258+
- Specify the number of visible cells:
228259
You need to specify the number of visible cells since this layout gives you the flexibility to show the next and previous cells.
229260
By default, the layout loads all of the cells in the collection view frame and that means it keeps all of them in memory.
230261
You can specify the number of cells that you need to show at a time by considering your design.
231262

263+
- Touches on cells:
264+
The way that this layout works is putting all the cells in the collectionview frame (doesn't matter which TransformView you use)
265+
and then it applies transforms on the target view (StackTransformView.cardView, ScaleTransformView.scalableView etc)
266+
so you can use `func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)` but only for one cell at the same time
267+
you can implement `func zPosition(progress: CGFloat) -> Int` to specify wich cell should be on top
268+
269+
if you would like to handle tap on multiple cells at the same time see [Handle touches]()
270+
232271

233272
## License
234273

0 commit comments

Comments
 (0)