paging in UIScrollView is a great feature, what I need here is to set the paging to a smaller distance, for example I want my UIScrollView to page less size that the UIScrollView frame width. Thanks
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- back button text does not change
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- How do you detect key up / key down events from a
There is a
UIScrollView
delegate method you can use. Set your class as the scroll view's delegate, and then implement the following:The velocity parameter is necessary to make sure the scrolling feels natural and doesn't end abruptly when a touch ends with your finger still moving. The cell width and cell spacing are the page width and spacing between pages in your view. In this case, I'm using a
UICollectionView
.Swift 4.1 solution that simplifies reusing:
Just conform to
ScrollViewCustomPageSize
protocol in your UIScrollView/UITableView/UICollectionView delegate and you are done, e.g.:For a fancy scrolling I also recommend to set
collectionView.decelerationRate = UIScrollViewDecelerationRateFast
I had the same problem short ago. My aproach was to add a second
UIScrollView
to the scrollview. So you can switch to the page. On that page it seems than if the page is bigger than the screen. I hope it works also in your situation. ;-)Sandro Meier
scroll.clipsToBounds = NO
Create a UIView subclass (e.g HackClipView) and override the hitTest:withEvent: method
Set the
HackClipView.clipsToBounds = YES
See this answer for more details
Update: As stated in lucius answer you can now implement the
UIScollViewDelegate
protocol and use the- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
method. As thetargetContentOffset
is a pointer. Using this method will not guarantee you the same result with scroll view pages as the user can scroll through many pages at once. But setting thedescelerationRate
tofast
will almost give you the same result