我有一个UIScrollView
里面的UIView
。出于自定义分页的目的,我已将此剪辑设置UIScrollView
为否,因此UIScrollView
仍会显示在UIView
.
[ 区域 A [UIScrollView] 区域 B ]
现在我希望区域 AB 能够触发UIScrollView's
触摸时的滚动事件。我记得有一个单行(类似[X addGestureRecognizer ...]
)可以解决问题,但我忘记了它是什么...如果有人会很棒可以告诉我那是什么!
这不会让您对滚动进行流畅的控制,就像您从UIScrollView
.
但是,您可以使用以下代码:
UISwipeGestureRecognizer *leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(viewSwiped:)];
[leftSwipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:leftSwipeGestureRecognizer];
[leftSwipeGestureRecognizer release];
UISwipeGestureRecognizer *rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(viewSwiped:)];
[rightSwipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:rightSwipeGestureRecognizer];
[rightSwipeGestureRecognizer release];
触发此方法:
- (void)viewSwiped:(UISwipeGestureRecognizer *)swipeGestureRecognizer {
switch (swipeGestureRecognizer.direction) {
case UISwipeGestureRecognizerDirectionLeft:
// Make your scroll view scroll
break;
case UISwipeGestureRecognizerDirectionRight:
// Make your scroll view scroll
break;
default:
// Do Nothing
break;
}
}
它将允许您检索滑动手势并UIScrollView
相应地分页。
其他两个解决方案可能会更好:
UIPanGestureRecognizer
上述相同的方法。它识别真正的平移手势,不仅是离散的滑动,而且手指和手指之间的同步的实现UIScrollView
会稍微复杂一些。UIScrollView
获取总宽度并自行管理分页,在跟踪viaUIView
的当前状态时重新计算您的步数。再一次,有点难。UIScrollView
UIScrollViewDelegate
希望这会有所帮助,
如果你想将UIScrollView
的滚动手势重定向到另一个视图,你可以这样做:
[paddingView addGestureRecognizer:scrollView.panGestureRecognizer];