Iphone 函数调用中的问题

Iphone 函数调用中的问题,iphone,uiview,uiscrollview,Iphone,Uiview,Uiscrollview,我有一个UIView,它的子视图是UIScrollView,而子视图又是UIImageView。我也能变焦。但我想在双击时调用另一个函数。我正在使用这个代码: - (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view { if(view == scrollView) { UITouch *touch = [touche

我有一个UIView,它的子视图是UIScrollView,而子视图又是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.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];

当添加到scrollView时,看起来bigImageView正在拉伸以适合scrollView。因此,您的方法没有被调用,因为您实际上是在点击bigImageView,而不是scrollView。

当bigImageView被添加到scrollView中时,它看起来正在拉伸以适应scrollView。因此,您的方法不会被调用,因为您实际上是在点击bigImageView,而不是scrollView。

最好使用UIgestureRecogizer来执行基本手势,如双击:

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

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

在您的
handleDoubleTap:
函数中,您可以调用任何您想要的方法。

最好使用UIgestureRecogizer进行基本手势,如双击:

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

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

在你的
handleDoubleTap:
函数中,你可以调用任何你想要的方法。

这也是我的第一个猜测。您可以通过在代码中放置NSLog语句来验证这一点,以查看执行的内容。试试看:如果(view==bigImageView),那也是我的第一个猜测。您可以通过在代码中放置NSLog语句来验证这一点,以查看执行的内容。try:if(view==bigImageView)