【问题标题】:UIScrollView Horizontal scrolling - Disable left scrollUIScrollView 水平滚动 - 禁用左滚动
【发布时间】:2011-02-18 12:17:04
【问题描述】:

如何禁用 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 没有被调用,我不知道为什么!!

谢谢

【问题讨论】:

  • 我也有同样的问题。你知道为什么即使 id canCancelContentTouches 设置为 YES 也不会调用 canCancelContentTouches 吗?

标签: iphone objective-c xcode


【解决方案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;
    }

}

【讨论】:

  • 无法在 Ipad 上运行。如果您快速滚动,它将向左滚动,然后在 [aScrollView setContentOffset: CGPointMake(oldX, aScrollView.contentOffset.y)];
【解决方案2】:

您应该处理滑动手势。

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

【讨论】:

  • 除非他当然想支持旧的 iOS 版本,在这种情况下他不应该。
猜你喜欢
  • 2015-11-18
  • 2010-11-06
  • 2013-01-31
  • 1970-01-01
  • 1970-01-01
  • 2012-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多