2013-01-15 25 views
0

在我的視圖層次結構的底部,我實現了touchesBegan方法。它觸發所有觸摸,除了單手指輕拍。這讓我相信,在層次結構中更高的地方,一種觀點是攔截/處理單指輕拍,但我無法找到我生活的觀點。有沒有一種很好的方法來調試呢?如何檢測哪個視圖正在處理我的水龍頭?

+0

你認爲則hitTest:withEvent:方法會有所幫助?看看這個線程http://stackoverflow.com/questions/4961386/event-handling-for-ios-how-hittestwithevent-and-pointinsidewithevent-are-r。 – sridevi

+0

不幸的是'hitTest:withEvent:'返回沒有接收到水龍頭的視圖。它似乎不受手勢識別器的影響。 –

回答

0

試試這個方法,如果它的工作了:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint touchLocation = [touch locationInView:self.contentView]; 

    for (UIView *view in self.contentView.subviews) 
    { 
     if ([view isKindOfClass:[MyCustomView class]] && 
      CGRectContainsPoint(view.frame, touchLocation)) 
     { 

     } 
    } 
} 
+0

不幸的是,'touchesMoved'不會被調用。單指輕敲不會觸及任何觸摸方法。它們都適用於多指水龍頭或平底鍋或除單指水龍頭以外的任何其他觸感。 –

相關問題