2

我的视图中有一个 UITableView。我的 UITableView 的名称是 tblTask​​。
我正在使用 touchesBegan 方法来获取我的视图的 x 和 y 坐标。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:self.view];

    NSLog(@"point........ %f .. %f",location.x,location.y);



}

但是当我从 tbltask 开始触摸事件时。即使 tbltask 是主视图的子视图,它也不会返回 location.x 和 location.y。

我也尝试禁用表格的滚动视图,但没有任何反应。
当我设置这个。

tbltask.userInteractionEnabled=NO;

然后它会给出坐标,但即使启用了 tbltask 交互,我也想要视图的坐标。

4

1 回答 1

4
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
     UITouch *touch ;
     touch = [[event allTouches] anyObject];
     if ([touch view] == self.view){
         CGPoint location = [touch locationInView:touch.view];
         NSLog(@"point........ %f .. %f",location.x,location.y);
      }
}
于 2012-04-18T17:39:59.907 回答