2012-09-21 96 views
4

我是通過編程方式添加子視圖的。每個子視圖我加入手勢reconognizer:如何知道是否已將UITapGestureRecognizer添加到子視圖

UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
    imageView.frame = CGRectMake((position*1024)+200,0,image.size.width,image.size.height); 
    UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] 
               initWithTarget:self action:@selector(singleFingerTap:)]; 
    singleFingerTap.numberOfTapsRequired = 1; 
    [imageView addGestureRecognizer:singleFingerTap]; 
    [singleFingerTap release]; 

但水龍頭沒有響應我怎麼能確認手勢已經將其添加到子視圖?

回答

3

你的代碼後補充一點:

NSLog(@"imageView.gestureRecognizers: %@", [imageView.gestureRecognizers description]); 

如果您正確添加gestureRecognizers它將打印每個描述到控制檯。如果不是,它將在控制檯中顯示(NULL)或一個空數組。


您還可以設置手勢識別委託:

[singleFingerTap setDelegate:self]; 

然後添加委託方法,並設置一個破發點,以確保它獲取調用:

的情況下,我
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { 
    NSLog(@"gestureRecognizerShouldBegin: called"); 
    return YES; 
} 

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { 
    NSLog(@"shouldReceiveTouch: called"); 
    return YES; 
} 
+0

想要獲取視圖水龍頭的屬性。如何實現此方法: - (void)viewTap:(UIGestureRecognizer *)發件人 – Juan

相關問題