2011-08-12 9 views
0

UIScrollViewをサブビューとして持つUIViewがあります。これにはサブビューとしてUIImageViewがあります。私もズームすることができます。しかし、私はダブルタップで別の関数を呼び出したい。このコードを使用して:関数の呼び出しでの問題

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view 
{ 
    if(view == scrollView) 
    { 
     UITouch *touch = [touches anyObject]; 
     if([touch tapCount]== 2) 
     { 
      [self setViewForProductDispaly]; 
      return YES; 
     } 

     } 
return NO; 

} 

上記の方法は、私がそれをタップするときに呼び出されていません。これは共鳴かもしれません。

私のscrollview

scrollView.hidden=NO; 
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0, 0.0,self.bounds.size.width,self.bounds.size.height)]; 

scrollView.maximumZoomScale = 3.0; 
scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack; 
scrollView.delegate =self; 
scrollView.bouncesZoom = YES; 
scrollView.delaysContentTouches=NO; 


bigImageView.autoresizesSubviews = YES; 
bigImageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 
bigImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0.0, 0.0, bigImg.size.width, bigImg.size.height)]; 
bigImageView.image = bigImg; 
bigImageView.userInteractionEnabled = YES; 

[scrollView addSubview:bigImageView]; 
[bigImageView release]; 

[self addSubview:scrollView]; 
[scrollView release]; 

答えて

2

その優れたダブルタップなどの基本的なジェスチャーのためUIGestureRecogizersを使用する:

UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc] 
         initWithTarget:self action:@selector(handleDoubleTap:)]; 

doubleTapGestureRecognizer.numberOfTapsRequired = 2; 
[self.scrollView addGestureRecognizer:doubleTapGestureRecognizer]; 

とあなたのhandleDoubleTap:機能であなたが好きなメソッドを呼び出すことができます。

1

bigImageViewは、それはそれに追加されますときscrollViewにフィットするようにストレッチされたように見えます。つまり、scrollViewではなく、bigImageViewを実際にタップしているため、メソッドが呼び出されません。

+1

それは私の最初の推測かもしれません。 NSLogステートメントをコード全体に配置して、何が実行されているかを確認するだけで、これを簡単に確認できます。 try:if(view == bigImageView) – ader

関連する問題