iPhone - UIScrollView ...检测触摸的坐标

Spa*_*Dog 6 iphone cocoa-touch uiscrollview ipad ios

可能重复:
UIScrollview获取触摸事件

是否可以检测手指触摸UIScrollView的位置?

我的意思是,假设用户以这种方式使用他的手指:点击和滚动,再次抬起手指,点击和滚动等.是否有可能知道CGPoint在哪里发生与自我相关的点击.查看滚动条是在?卷轴占据了整个self.view.

谢谢.

ber*_*ium 12

你可以用手势识别器来做到这一点.用于检测单击位置使用UITapGestureRecognizer

UITapGestureRecognizer *tapRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)] autorelease];
[myScrollView addGestureRecognizer:tapRecognizer];

- (void)tapAction:(UITapGestureRecognizer*)sender{ 
    CGPoint tapPoint = [sender locationInView:myScrollView];
    CGPoint tapPointInView = [myScrollView convertPoint:tapPoint toView:self.view];
}
Run Code Online (Sandbox Code Playgroud)

要将其转换tapPoint为self.view,您可以使用convertPoint:toView:UIView类中的方法