获取视图的X和Y坐标

时间:2012-04-18 10:06:07

标签: iphone

我在My View中有一个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交互,我也想要视图的坐标。

1 个答案:

答案 0 :(得分: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);
      }
}
相关问题