2011-07-01 8 views
0

私はフォーラムを読んでいて、私は同様の問題を見つけることができなかったので、このメッセージを投稿しています。私はタップとダブルタップ(これは標準的なものです)を区別することができる必要がありますが、私の問題は、私が別のScrollView内にスクロールビューを持っている理由が何であれです。そこで、touchedBeginメソッドを呼び出すためにScrollViewをサブクラス化しなければなりませんでした。ScrollView内でシングル/ダブルタップをキャプチャする際の問題

私はPhotoViewController(BaseViewControllerのサブクラス)というクラスがあります。このクラスには、CustomScrollView(ScrollViewのサブクラス)という別のクラスが含まれています。私は、touchesBeginメソッドをオーバーライドし、ユーザーが行ったタッチをキャプチャするために、このCustomScrollViewをScrollViewからサブクラス化する必要がありました。

touchesBeginメソッド内でreturn [super touchesBegan:touches withEvent:event]のようなものを使用してcustomScrollViewからtouchesBeginメソッドを呼び出そうとしましたが、PhotoViewController内のtouchesBeginメソッドが呼び出されたときにパラメータが空です

@class PhotoViewController 
@interface PhotoViewController : BaseViewController <UIScrollViewDelegate> { 

    CustomScrollView*   myScrollView; 

} 

@implementation PhotoViewController 

... 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 

    NSUInteger tapCount = [touch tapCount]; 

    switch (tapCount) { 
     case 1: 

      [self performSelector:@selector(singleTapMethod) withObject:nil afterDelay:.4]; 
      break; 
     case 2: 

      [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapMethod) object:nil]; 
      [self performSelector:@selector(doubleTapMethod) withObject:nil afterDelay:.4]; 
      break; 
     default: 
      break; 
    } 

} 

クラスCustomScrollViewがある(CustomScrollView.h):ユーザーが、私は必要なものを正確にシングルまたはダブルタップ、)

を作った場合、私はPhotoViewControllerと呼ばれるクラスを、持っている

@interface CustomScrollViewPhoto : UIScrollView { 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 

@end 

、それは実装がこの(CustomScrollView.m)であるのです。

@implementation CustomScrollViewPhoto 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  
    [self.superview touchesBegan:[NSSet set] withEvent:event]; 
    return [super touchesBegan:touches withEvent:event]; 
} 

は私が何をしたいのかと間違った方向に行くのだろうか?たぶん、CustomScrollViewクラスのタップ/ダブルタップをキャプチャする必要があります(これはうまくいきます!)、そこから@ Selectorなどを使用してPhotoViewControllerの適切なメソッドを呼び出しますか?

読んでいただきありがとうございます!

答えて

0

あなたは間違ったルートを行っていると思います(わずかです)。私は写真ビューアで非常に似たようなことを行い、CustomScrollViewでタッチをキャプチャします。 PhotoViewControllerで何もする必要はありません。

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

    UITouch *touch = [touches anyObject]; 

    if(touch.tapCount == 2) 
    { 
     if (self.zoomScale == self.minimumZoomScale) 
     { 
      //Zoom where the user has clicked from 
      CGPoint pos = [touch locationInView:self]; 
      [self zoomToRect:CGRectMake((pos.x - 5.0)/self.zoomScale, (pos.y-5.0)/self.zoomScale, 10.0, 10.0) animated:YES]; 
     } 
     else 
     { 
      //Zoom back out to full size 
      [self setZoomScale:self.minimumZoomScale animated:YES]; 
     } 
    } 
} 
+0

こんにちは、それは確かに解決しました! Txs! – nachoman

関連する問題