【发布时间】:2012-08-29 03:47:32
【问题描述】:
我在 UIScrollView 中有一个 UIView demoView。我想垂直滚动 UIScroll 视图而不是水平滚动。我将 UISwipeGestureRecognizer 添加到 UIView。代码是(这里的self是UIScrollView):
self.demoView.userInteractionEnabled = YES;
UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(rightSwipeLineChart:)];
rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
[self.demoView addGestureRecognizer:rightSwipe];
UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(leftSwipeLineChart:)];
[self.demoView addGestureRecognizer:leftSwipe];
结果是我只能检测到左滑动手势,无法检测到右滑动手势。我的代码有什么问题?谢谢。
【问题讨论】:
-
也许
self这里是视图控制器? -
self 这里是 UIScrollView 的子类。我使用 .xib 文件。这个子类与 .xib 捆绑在一起。
-
为什么要添加滑动识别器?如果您不希望滚动视图水平滚动,您应该指定 contentSize 为 0 宽度(或小于视口宽度)。
标签: objective-c uiscrollview uiswipegesturerecognizer