2011-08-12 46 views
0

我有一個UIScrollView作爲子視圖,它又有一個UIImageView作爲其子視圖的UIView。我也可以放大。但是我想在雙擊時調用另一個功能。即時通訊使用此代碼:在調用函數的問題

- (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; 

} 

地,上述方法沒有得到當我點擊it.What可能是這個振振有辭調用。

我的滾動視圖

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被拉伸以適應滾動視圖,當它添加到它。所以你的方法沒有被調用,因爲你真的在攻擊bigImageView,而不是scrollView。

+1

這也是我的第一個猜測。您可以通過在整個代碼中放置NSLog語句來驗證這一點,以查看執行的內容。試試:if(view == bigImageView) – ader