Skip to content
This repository was archived by the owner on Dec 18, 2017. It is now read-only.
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
16 changes: 15 additions & 1 deletion AKPickerView/AKPickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ private class AKCollectionViewLayout: UICollectionViewFlowLayout {
return attributes
}
}

override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
var offsetAdjustment: CGFloat = CGFloat.greatestFiniteMagnitude
let horizontalCenter: CGFloat = proposedContentOffset.x + (self.collectionView!.bounds.width / 2.0)
let targetRect = CGRect(x: proposedContentOffset.x, y: 0.0, width: self.collectionView!.bounds.size.width, height: self.collectionView!.bounds.size.height)
let array:[UICollectionViewLayoutAttributes] = self.layoutAttributesForElements(in: targetRect)!
for layoutAttributes: UICollectionViewLayoutAttributes in array {
let itemHorizontalCenter: CGFloat = layoutAttributes.center.x
if abs(itemHorizontalCenter - horizontalCenter) < abs(offsetAdjustment) {
offsetAdjustment = itemHorizontalCenter - horizontalCenter
}
}
return CGPoint(x: proposedContentOffset.x + offsetAdjustment, y: proposedContentOffset.y)
}

}

Expand Down Expand Up @@ -233,7 +247,7 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD
public weak var dataSource: AKPickerViewDataSource? = nil
/// Readwrite. Delegate of picker view.
public weak var delegate: AKPickerViewDelegate? = nil {
didSet(delegate) {
didSet {
self.intercepter.delegate = delegate
}
}
Expand Down