0

我有一个UIScrollView里面的UIView。出于自定义分页的目的,我已将此剪辑设置UIScrollView为否,因此UIScrollView仍会显示在UIView.

[ 区域 A [UIScrollView] 区域 B ]

现在我希望区域 AB 能够触发UIScrollView's触摸时的滚动事件。我记得有一个单行(类似[X addGestureRecognizer ...])可以解决问题,但我忘记了它是什么...如果有人会很棒可以告诉我那是什么!

4

2 回答 2

1

这不会让您对滚动进行流畅的控制,就像您从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相应地分页。

其他两个解决方案可能会更好:

  1. 您可以使用与UIPanGestureRecognizer上述相同的方法。它识别真正的平移手势,不仅是离散的滑动,而且手指和手指之间的同步的实现UIScrollView会稍微复杂一些。
  2. 您可以让您自己UIScrollView获取总宽度并自行管理分页,在跟踪viaUIView的当前状态时重新计算您的步数。再一次,有点难。UIScrollViewUIScrollViewDelegate

希望这会有所帮助,

于 2013-02-28T12:04:07.427 回答
1

如果你想将UIScrollView的滚动手势重定向到另一个视图,你可以这样做:

[paddingView addGestureRecognizer:scrollView.panGestureRecognizer];
于 2013-02-28T14:45:29.440 回答