Skip to content

Commit e4f57fd

Browse files
committed
swipe to only one item
1 parent f9c1774 commit e4f57fd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/FSPageViewLayout.swift

+8
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ class FSPagerViewLayout: UICollectionViewLayout {
168168
offset += self.itemSpacing * (velocity.x)/abs(velocity.x)
169169
}
170170
}
171+
172+
let targetIndex = Int(offset/self.itemSpacing)
173+
let originalIndex = Int(round(originalContentOffsetX/self.itemSpacing))
174+
if targetIndex < originalIndex - 1 {
175+
offset = CGFloat(originalIndex - 1)*self.itemSpacing
176+
} else if targetIndex > originalIndex + 1 {
177+
offset = CGFloat(originalIndex + 1)*self.itemSpacing
178+
}
171179
return offset
172180
}()
173181
let proposedContentOffsetY: CGFloat = {

0 commit comments

Comments
 (0)