I have a collectionView Cell that is of the same size of my CollectionView i.e. one Cell at a time is displayed on the screen and I want minimum separation of 10 between cells, the problem is when I scroll the cell the cells aren't properly fitting the whole screen, and the shifting of cell is increased after every scroll. (Check screenshots for better understanding)
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
I assume you have set
pagingEnabled
for the collection view. It inherits this property fromUIScrollView
(becauseUICollectionView
is a subclass ofUIScrollView
).The problem is that the collection view uses its own width (320 points in your post) as the width of a page. Each of your cells is the same width as the collection view, but then you have a 10 point “gutter” between the cells. This means that the distance from the left edge of cell 0 to the left edge of cell 1 is 320 + 10 = 330 points. So when you scroll to show cell 1, the collection view stops scrolling at offset 320 (its own width), but cell 1 actually starts at offset 330.
The easiest fix is probably to turn off
pagingEnabled
and implement paging yourself by overridingscrollViewWillEndDragging(_:withVelocity:targetContentOffset:)
in your collection view delegate, like this:You'll also want to set the item size to match the device screen size, and set the deceleration rate to fast:
Result:
The reason is that you have not taken the
minimum separation of 10
while setting width of the cell(320). Hence this10
is getting accumulated each time to scroll.So you have to subtract 10 out of 320 while setting the width, so the width should be 310 IMO.