调用函数的问题

时间:2011-08-12 08:18:59

标签: iphone uiview uiscrollview

我有一个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];

2 个答案:

答案 0 :(得分:2)

最好将UIGestureRecogizers用于基本手势,例如双击:

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

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

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

答案 1 :(得分:1)

看起来bigImageView在添加到它时会适应scrollView。所以,你的方法没有被调用,因为你实际上是在点击bigImageView而不是scrollView。