2012-10-25 2 views
1

UITapGestureRecognizerUIView의 서브 클래스 인 내 보드 클래스에 추가합니다. Tap 이벤트의 위치를 ​​얻고 싶습니다. 여기 내 사용자 지정 초기화 방법 :UITapGestureRecognizer는 location.x 값으로 0을 반환합니다.

- (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 초보자이기 때문에 초보자 실수 일뿐입니다. 나는 수퍼

한 곳

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer 
{ 
    CGPoint location = [recognizer locationInView:[recognizer.view self]]; 
    CGFloat x = location.x; 
    NSLog(@"testing = %f", (double)x); 
} 

내가 자기를 추가하는 데 필요한 :

답변

1

내가 그것을 고정하는 방법이다
관련 문제