UIScrollView Horizontal scrolling - Disable left scroll
How can I disable scrolling left on a UIScrollview. This is so users can only scroll right?
Thanks
*** UPDATE *****
This is what I have now. I have subclassed UIScrollView and overwritten the following methods
@implementation TouchScrollView
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view {
NSLog(@"touchesShouldBegin: I was touched!");
return YES;
}
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
NSLog(@"touchesShouldCancelInContentView: I was touched!");
return NO;
}
In my vi开发者_Go百科ewController I have also set the following attributes:
scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = YES;
TouchesShouldBegin is being called but touchesShouldCancelInContentView is not being called and I cant figure out why!!
Thanks
just add this in your UIViewController UIScrollViewDelegate
float oldX; // here or better in .h interface
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView
{
if (scrollView.contentOffset.x < oldX) {
[aScrollView setContentOffset: CGPointMake(oldX, aScrollView.contentOffset.y)];
} else {
oldX = aScrollView.contentOffset.x;
}
}
You should handle swipe gestures.
Check similar question here: iOS Advanced Gestures: Getting Swipe Direction Vector
精彩评论