开发者

UIScrollView Horizontal scrolling - Disable left scroll

开发者 https://www.devze.com 2023-02-11 16:03 出处:网络
How can I disable scrolling left on a UIScrollview. This is so users can only scroll right? Thanks *** UPDATE *****

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

0

精彩评论

暂无评论...
验证码 换一张
取 消