UIScrollView 决定拖动和点击 [英] UIScrollView decide between drag and tap

查看:52
本文介绍了UIScrollView 决定拖动和点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定 UIScrollView 内视图上的单个选项卡.问题是 UIScrollview 捕获了所有手势.

I am trying to determine a Single Tab on a View inside of a UIScrollView. The Problem is that The UIScrollview catches all the gestures.

到目前为止我尝试过的:我在 UIScrollView 中重写了以下方法:

What I tried so far: I override the following method in my UIScrollView:

-(BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
    UITouch *touch = [touches anyObject];
    if([touch tapCount]== 2) return YES;

    return NO;
}

这很好用,我现在可以在我的 UIView 上访问 UITapGestureRecognize,不幸的是我只能检测双击,因为 [touch tapCount] == 1 总是被调用(在 UIScrollView 中拖动或放大).但实际上 UIScrollview 不需要Single-Tap-Function"

This works fine, I can now reach the UITapGestureRecognize on my UIView, unfortunately I can only detect double-taps because the [touch tapCount] == 1 is always beeing called (dragging or zooming in the UIScrollView). But actually the UIScrollview does not need the "Single-Tap-Function"

有没有办法在此方法中在拖动(滚动或缩放)和单击之间做出决定?我找不到它..

Is there a way to decide between a drag (Scroll or zoom) and a single Tap inside this method? I cant find it..

-(BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view

提前致谢法比

推荐答案

听起来您只希望点击识别器在触摸不滚动滚动视图时成功.这很容易,因为滚动视图使用平移手势识别器进行滚动.在 iOS 5 上,你可以这样做:

It sounds like you only want the tap recognizer to succeed if the touch doesn't scroll the scroll view. This is pretty easy because the scroll view uses a pan gesture recognizer for scrolling. On iOS 5, you can just do this:

[self.tapRecognizer requireGestureRecognizerToFail:self.scrollView.panGestureRecognizer];

如果你想支持旧版本的 iOS,你必须这样做:

If you want to support older versions of iOS, you have to do this:

for (UIGestureRecognizer *recognizer in self.scrollView.gestureRecognizers) {
    if ([recognizer isKindOfClass:[UIPanGestureRecognizer class]])
        [self.tapRecognizer requireGestureRecognizerToFail:recognizer];

这篇关于UIScrollView 决定拖动和点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆