Ok, I implemented it this way and it works quite well:
//this is the percentage of page I need to drag to trigger the paging
#define PAGING_THREESHOLD 0.6
//this enum is to keep track of the scrolling direction
typedef enum ScrollDirection {
ScrollDirectionNone,
ScrollDirectionRight,
ScrollDirectionLeft,
ScrollDirectionUp,
ScrollDirectionDown,
ScrollDirectionCrazy,
} ScrollDirection;
//this is to avoid the intertial scrolling
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint *)targetContentOffset {
*targetContentOffset = scrollView.contentOffset;
}
//here is the custom paging code
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
CGPoint destinationOffset = scrollView.contentOffset;
CGFloat y = (int)destinationOffset.y % (int)scrollView.height;
if (_scrollDirection == ScrollDirectionDown){
CGFloat delta = scrollView.height - (scrollView.height - y);
delta = delta / scrollView.height;
NSUInteger currentPage = scrollView.contentOffset.y / scrollView.size.height;
if (delta > PAGING_THREESHOLD && currentPage != scrollView.verticalPageCount - 1){
//go to next page
destinationOffset = CGPointMake(destinationOffset.x, (currentPage + 1) * scrollView.height);
}else{
destinationOffset = CGPointMake(destinationOffset.x, currentPage * scrollView.height);
}
}else if (_scrollDirection == ScrollDirectionUp){
CGFloat delta = scrollView.height - y;
delta = delta / scrollView.height;
NSUInteger currentPage = scrollView.contentOffset.y / scrollView.size.height;
if (delta > PAGING_THREESHOLD){
//go to next page
destinationOffset = CGPointMake(destinationOffset.x, currentPage * scrollView.height);
}else{
destinationOffset = CGPointMake(destinationOffset.x, (currentPage + 1) * scrollView.height);
}
}
if (!CGPointEqualToPoint(destinationOffset, scrollView.contentOffset)){
[scrollView setContentOffset:destinationOffset animated:YES];
}
}
//here the scrolldirection is calculated
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (self.lastContentOffset.x > scrollView.contentOffset.x){
_scrollDirection = ScrollDirectionRight;
} else if (self.lastContentOffset.x < scrollView.contentOffset.x){
_scrollDirection = ScrollDirectionLeft;
} else if (self.lastContentOffset.y > scrollView.contentOffset.y){
_scrollDirection = ScrollDirectionUp;
} else if (self.lastContentOffset.y < scrollView.contentOffset.y){
_scrollDirection = ScrollDirectionDown;
} else{
_scrollDirection = ScrollDirectionNone;
}
self.lastContentOffset = scrollView.contentOffset;
}