UIScrollView水平滚动 - 禁用左滚动

时间:2011-02-18 12:17:04

标签: iphone objective-c xcode

如何在UIScrollview上禁用左侧滚动。这样用户只能向右滚动吗?

由于

** * 更新 * ****

这就是我现在所拥有的。我已经将UIScrollView子类化并覆盖了以下方法

@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;
}

在我的viewController中,我还设置了以下属性:

scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = YES;

正在调用TouchesShouldBegin但是没有调用touchesShouldCancelInContentView,我无法弄清楚为什么!!

由于

2 个答案:

答案 0 :(得分:1)

只需在你的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;
    }

}

答案 1 :(得分:0)

您应该处理滑动手势。

点击此处查看类似问题:iOS Advanced Gestures: Getting Swipe Direction Vector