2011-06-27 18 views
1

私はUIViewにいくつかのドラッグを処理するために(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event、および(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)eventを使用しています。このUIViewしかしUIViewのサブビューとして一部UIButtonsを有しており、ユーザが(UIView上にもある)UIButton上に触れるとタッチメソッドは呼び出されません。UIButtonでタッチしたときのUIViewのタッチを検出する方法は?

私はUIViewのタッチメソッドが常に呼び出され、まだUIButtonsが動作する必要があります、どのように私はこれを達成することができますか?

+0

素晴らしい作品 – Aravindhan

答えて

3

問題なく、私はすでに私の質問を解決しました。

方法も、このようにボタンでタッチメソッドをオーバーライドすることです:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    touchMoved = NO; 
    [[self superview] touchesBegan:touches withEvent:event]; 
    [super touchesBegan:touches withEvent:event]; 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    touchMoved = YES; 
    [[self superview] touchesMoved:touches withEvent:event]; 
    [super touchesMoved:touches withEvent:event]; 
} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    if (!touchMoved) [super touchesEnded:touches withEvent:event]; 
} 

touchMoved変数は、それがボタンに直接タッチした場合やタッチがドラッグに意味された場合、追跡するためのものですスーパービュー。 UIControlEventTouchUpInsideを使用しているので、タッチの動きを追跡したときにtouchesEndedを無効にすると正常に動作します。

+0

......あなたの前の答えを受け入れるようにしてください!ありがとうございました!! – DZenBot

関連する問題