我正在为UIView
的子类添加UITapGestureRecognizer
。我想获得TAP活动的位置。这是我的自定义初始方法:
- (void)setup
{
[self setUserInteractionEnabled:YES];
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleSingleTap:)];
[self addGestureRecognizer:singleFingerTap];
...
}
这是我的单fingertap方法:
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
CGPoint location = [recognizer locationInView:[recognizer.view superview]];
CGFloat x = location.x;
NSLog(@"testing = %f", (double)x);
}
这是我在不同位置进行多个水龙头的输出:
2012-10-24 22:49:53.077 TicTacToe[15561:f803] testing = 0.000000
2012-10-24 22:49:53.971 TicTacToe[15561:f803] testing = 0.000000
2012-10-24 22:49:54.671 TicTacToe[15561:f803] testing = 0.000000
很明显,我的SinglefingerTap方法被调用,但是该位置一直在说X坐标的位置为0。我是一名Objective-C Newbie,所以这可能是一个新手错误。
这就是我修复的方式:
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
CGPoint location = [recognizer locationInView:[recognizer.view self]];
CGFloat x = location.x;
NSLog(@"testing = %f", (double)x);
}
我需要添加自我的自我