- When scrolling, the cards magnify when they get to the center.
- You can tap and hold on a card, swipe up to 'Like' it. Right after, it will scroll to next one.
- You can tap and hold on a card, swipe down to 'Dismiss' it. After, it will scroll to next card.
- When tapping on the centered card, it will be opened a chat room with the user the card represents.
- When tapping on the side cards, it will scroll to them.
- When swiping up or down on the side cards, they won't be liked or dismissed. Just moved.
github "ppacie/SwipingCarousel"
-
Import
SwipingCarousel
module to yourViewController
andCollectionViewCell
classes.import SwipingCarousel
-
Make your
CollectionViewCell
subclass ofSwipingCarouselCollectionViewCell
.class MyCollectionViewCell: SwipingCarouselCollectionViewCell { }
-
Conform to
SwipingCarouselDelegate
protocol methodsfunc cellSwipedDown()
andfunc cellSwipedUp()
. e.g.extension MyCollectionViewController: SwipingCarouselDelegate { func cellSwipedUp(_ cell: UICollectionViewCell) { ... } func cellSwipedDown(_ cell: UICollectionViewCell) { ... } }
-
Finally, you will need to set it as your CollectionView's custom layout: You can do it either in the Interface Builder OR programmatically.
- Interface Builder: Go to your Storyboard file and select the Controller where you have the CollectionView. Later select the CollectionView in the Document Outline and set the
SwipingCarouselFlowLayout
as the Custom Layout in the Attributes Inspector and set the Module toSwipingCarousel
.
- Programmaticaly:
Add the following line in the
viewDidLoad()
of yourCollectionViewController
(the ViewController that contains your CollectionView):
collectionView.setCollectionViewLayout(SwipingCarouselFlowLayout(), animated: false)
weak public var delegate: SwipingCarouselDelegate?
An object that supports the SwipingCarouselDelegate protocol and can respond to swiping events.
public var deleteOnSwipeDown = false
Indicates weather to remove the SwipingCarouselCell cell from view or to get it back to the original position when swiping down. Default behavior is to get back to original position.
public var deleteOnSwipeUp = false
Indicates weather to remove the SwipingCarouselCell cell from view or to get it back to the original position when swiping up. Default behavior is to get back to original position.
Check the ExampleProject folder to see how it works.
Sure, you are able to customize the layout by overriding the UICollectionViewDelegateFlowLayout
methods you desire.
e.g.
extension MyCollectionViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 200, left: 120, bottom: 200, right: 120)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 150.0, height: 230.0)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 50.0
}
}
Also if you set the layout programmatically you will be allowed to change the activeDistance
value. This property will get you access to modify the layoutAttributes of the collectionView. It represents the distance from the center where the cell/item will start zooming in and out. Default value is 200.0
let layout = SwipingCarouselFlowLayout()
layout.activeDistance = 50
collectionView.setCollectionViewLayout(layout, animated: false)