Skip to content

Commit ada22e5

Browse files
committed
Updated Readme
1 parent ed38514 commit ada22e5

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

README.md

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,66 @@ override func viewDidLoad() {
3636
// configure centeredCollectionView properties
3737
centeredCollectionView.itemSize = CGSize(width: 100, height: 100)
3838
centeredCollectionView.minimumLineSpacing = 20
39-
centeredCollectionView.scrollToEdgeEnabled = true
4039

4140
// get rid of scrolling indicators
4241
centeredCollectionView.showsVerticalScrollIndicator = false
4342
centeredCollectionView.showsHorizontalScrollIndicator = false
4443
}
44+
45+
// delegate and datasource extensions
46+
...
47+
48+
```
49+
50+
## Scrolling to an Edge on Touch 🎡
51+
![scrollToEdgeEnabled](/GitHub/ScrollToEdge.gif)
52+
53+
Heres how you could trigger a scroll animation when a touch happens on an item that isn't the `currentCenteredPage`:
54+
55+
```swift
56+
extension ViewController: UICollectionViewDelegate {
57+
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
58+
59+
// if the currentCenteredPage isn't the one that was touched
60+
if scrollToEdgeEnabled,
61+
let currentCenteredPage = centeredCollectionView.currentCenteredPage,
62+
currentCenteredPage != indexPath.row {
63+
64+
// trigger a scrollTo(index: animated:)
65+
centeredCollectionView.scrollTo(index: indexPath.row, animated: true)
66+
}
67+
}
68+
}
4569
```
4670

4771
## Customize 🖌
4872
You can use all properties inherited from `UICollectionView`.
4973

5074
**CenteredCollectionView specific properties**:
5175

52-
* **minimumLineSpacing** amount of space between each cell
76+
* **`minimumLineSpacing`** amount of space between each cell
5377
```Swift
5478
var minimumLineSpacing: CGFloat { get set }
5579
// default: 10
5680
```
5781

58-
* **itemSize** size of each cell (⚠️ required)
82+
* **`itemSize`** size of each cell. **⚠️ required for use**
5983
```Swift
6084
var itemSize: CGSize { get set }
6185
```
6286

63-
* **scrollDirection** direction of scrolling **(supports vertical)**
87+
* **`currentCenteredPage`** calculates the current centred page/item
6488
```Swift
65-
var scrollDirection: UICollectionViewScrollDirection { get set }
66-
// default: .horizontal
89+
var currentCenteredPage: Int? { get }
6790
```
6891

69-
* **scrollToEdgeEnabled** if `true` will scroll on touch to the edge of the cell that is peeking out from a side (wont trigger delegate `didSelectItemAt indexPath:` events)
92+
* **`scrollDirection`** direction of scrolling **(supports vertical)**
7093
```Swift
71-
var scrollToEdgeEnabled: Bool { get set }
72-
// default: false
94+
var scrollDirection: UICollectionViewScrollDirection { get set }
95+
// default: .horizontal
7396
```
74-
![scrollToEdgeEnabled](/GitHub/ScrollToEdge.gif)
7597

76-
* **scrollTo(index: animated:)** programatically scrolls to a cell at a specified index.
98+
* **`scrollTo(index: animated:)`** programatically scrolls to a cell at a specified index.
7799
```Swift
78100
func scrollTo(index: Int, animated: Bool)
79101
```

0 commit comments

Comments
 (0)