How can I force a UIScrollView in which paging and scrolling are on to only move vertically or horizontally at a given moment?
My understanding is that
I used following method to solve this problem, hope it helps you.
First define following variables in your controllers header file.
CGPoint startPos;
int scrollDirection;
startPos will keep the contentOffset value when your delegate receives scrollViewWillBeginDragging message. So in this method we do this;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
startPos = scrollView.contentOffset;
scrollDirection=0;
}
then we use these values to determine users intended scroll direction in scrollViewDidScroll message.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollDirection==0){//we need to determine direction
//use the difference between positions to determine the direction.
if (abs(startPos.x-scrollView.contentOffset.x)
finally we have to stop all update operations when user end dragging;
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if (decelerate) {
scrollDirection=3;
}
}