获取TouchDragInside方法内的触摸位置

时间:2014-02-09 00:31:56

标签: ios iphone xcode

如果没有传递给方法的事件参数,我如何在TouchDragInside方法中获取触摸位置?

显然这不起作用:

- (IBAction)touchDragInsideDblTapSignBut:(id)sender {
   UITouch *touch = [[event allTouches] anyObject];
   CGPoint location = [touch locationInView:touch.view];
}

谢谢,

1 个答案:

答案 0 :(得分:0)

所以在我的viewDidLoad中我不得不添加:

[_dblTapSignAddBut addTarget:self action:@selector(touchDragInsideDblTapSignButE:event:) forControlEvents:UIControlEventTouchDragInside];

然后创建一个void方法:

- (void) touchDragInsideDblTapSignButE:(id)sender event:(UIEvent *)event {
   UITouch *touch = [[event allTouches] anyObject];
   CGPoint location = [touch locationInView:touch.view];
   NSLog(@"Location x%f y%f",location.x,location.y);
}