UITapGestureRecognizer
のサブクラスである Board クラスに を追加していUIView
ます。Tap イベントの場所を取得したい。これが私のカスタムinitメソッドです:
- (void)setup
{
[self setUserInteractionEnabled:YES];
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleSingleTap:)];
[self addGestureRecognizer:singleFingerTap];
...
}
ここに私のsingleFingerTapメソッドがあります:
- (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の初心者なので、おそらく初心者の間違いです。