我使用UITapGestureRecognizer
來檢測哪個UIView是在我的屏幕上點擊的,但由於某種原因,它僅檢測到父級視圖點擊,例如僅在代碼日誌下方顯示父視圖標記。我如何檢測出現在主視圖上的子視圖水龍頭。請建議。UITapGestureRecognizer用於檢測在我的屏幕上點擊哪個UIView
Inside View did load :-
UITapGestureRecognizer *viewTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionForViewTapped:)];
[self.view addGestureRecognizer:viewTapRecognizer];
-(void) actionForViewTapped:(UITapGestureRecognizer*)sender {
NSLog(@"view tapped");
UIView *view = sender.view;
NSLog(@"view tag is %lu", view.tag); //Always prints parent view tag.
if(view.tag == 10){
NSLog(@"tag1 tapped"); // not called
}
if(view.tag == 20){
NSLog(@"tag 2 tapped"); // not called
}
}