iOS:在Scrollview中触摸事件

时间:2013-01-18 10:40:02

标签: ios objective-c scrollview

我已经尝试了很多事情来触及UIScrollView,但我还没知道怎么做。

实际上我想在UIScrollView内触摸并获取子视图的位置(我已触及)。

1 个答案:

答案 0 :(得分:0)

你可以用手势识别器来做到这一点。要检测单击位置,请使用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转换为self.view,您可以在UIView类中使用convertPoint:toView:方法