MSPeekCollectionViewDelegateImplementation
Current design trends require complex designs which allow horizontal scrolling inside vertical scrolling. So to show the users that they can scroll vertically, a peeking item should be shown on the side. This library does exactly that. I wrote this library because there's no pod that does this simple feature. Also, other libraries require me to inherit from a UICollectionViewController, which doesn't give alot of freedom if I'm inheriting from other View Controllers.
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
- XCode 9.3
- Swift 3.2
This pod will probably work on older versions of XCode but I haven't tested it.
Installation
MSPeekCollectionViewDelegateImplementation is available through CocoaPods. To install
it, simply add the following line to your Podfile:
Usage
Storyboard
-
Drag-Drop a
UICollectionView
-
Set the reuse identifier for the collection view's cell to
Cell
-
Create a reference for the collection view
-
Bind collection view to outlet
-
Import library
- Create a variable of type
MSPeekCollectionViewDelegateImplementation
- In
viewDidLoad()
, Configure thecollectionView
for peek behavior:
- In
viewDidLoad()
, initialize the delegate using the basic initializer:
Or you can use whatever arguments from the ones below (Can be combined together as needed):
- In
viewDidLoad()
, set the collection view's delegate:
- Create the data source implementation as an extension for the
ViewController
- In
viewDidLoad()
, Set the collection view's data source toself
Working Example
Features
Getting the offset of a specific index
The implementation introduces a function (scrollView(_:,contentOffsetForItemAtIndex:) -> CGFloat
) to get the content offset of an item at a specific index. This can be helpful if you want to scroll the collection view programmatically to a specific index (Maybe create a carousel with a timer). You can do that by using the following code:
Customization
Vertical Scroll Direction
The implementation supports collection views with vertical directions and will automatically position cells correctly, you can set the scrolling and peeking to be vertical using:
Or alternatively:
Subclassing
You can subclass the delegate implementation to integrate other features to it, or listen to certain events:
Note: Make sure you call super on overriden functions (Unless you know what you're doing)