iPhone - UIScrollView ...检测触摸的坐标 [英] iPhone - UIScrollView... detecting the coordinates of a touch

查看:203
本文介绍了iPhone - UIScrollView ...检测触摸的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

UIScrollview获取触摸事件

可以检测UIScrollView手指触摸?

Is it possible to detect where in a UIScrollView the finger touched?

我的意思是,假设用户以这种方式使用他的手指:轻敲和滚动,提起手指和再次,轻敲和滚动等。它可能知道点击发生的CGPoint相对于self.view滚动是在?卷轴占据整个self.view。

I mean, suppose the user uses his finger in this way: taps and scroll, lifts the finger and again, taps and scroll, etc. Is it possible to know the CGPoint where the taps happened in relation to the self.view the scroller is in? The scroller occupies the whole self.view.

谢谢。

推荐答案

你可以用手势识别器。对于检测单击位置使用 UITapGestureRecognizer

You can do it with gesture recognizers. For detect single tap location use 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];
}

要转换 tapPoint to self.view您可以使用 convertPoint:toView: 方法UIView类

To convert that tapPoint to self.view you can use convertPoint:toView: method in UIView class

这篇关于iPhone - UIScrollView ...检测触摸的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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