Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions UPCarouselFlowLayout/UPCarouselFlowLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public enum UPCarouselFlowLayoutSpacingMode {
case overlap(visibleOffset: CGFloat)
}

public enum UPCarouselFlowInitialSpacing {
case startFromZero
case equalSpace
case customSpace(initialX: CGFloat)
}


open class UPCarouselFlowLayout: UICollectionViewFlowLayout {

Expand All @@ -29,6 +35,7 @@ open class UPCarouselFlowLayout: UICollectionViewFlowLayout {
@IBInspectable open var sideItemAlpha: CGFloat = 0.6
@IBInspectable open var sideItemShift: CGFloat = 0.0
open var spacingMode = UPCarouselFlowLayoutSpacingMode.fixed(spacing: 40)
open var initialSpacing = UPCarouselFlowInitialSpacing.equalSpace

fileprivate var state = LayoutState(size: CGSize.zero, direction: .horizontal)

Expand Down Expand Up @@ -59,7 +66,20 @@ open class UPCarouselFlowLayout: UICollectionViewFlowLayout {

let yInset = (collectionSize.height - self.itemSize.height) / 2
let xInset = (collectionSize.width - self.itemSize.width) / 2


switch initialSpacing {
case .startFromZero:
self.sectionInset = UIEdgeInsets(top: yInset, left: 0, bottom: yInset, right: xInset)
case .equalSpace:
self.sectionInset = UIEdgeInsets(top: yInset, left: xInset, bottom: yInset, right: xInset)
case .customSpace(let initialX):
self.sectionInset = UIEdgeInsets(top: yInset, left: initialX, bottom: yInset, right: xInset)
}

self.sectionInset = UIEdgeInsets.init(top: yInset, left: xInset, bottom: yInset, right: xInset)



let side = isHorizontal ? self.itemSize.width : self.itemSize.height
let scaledItemOffset = (side - side*self.sideItemScale) / 2
Expand Down