I have a UIView that has a UIScrollView as a subview, which in turn has a UIImageView as its subv开发者_JS百科iew . I am able to zoom also. But I want to call another function on double tap. Im using this code:
- (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;
}
The above method is not getting called when i tap it.What might be the reson for this.
my 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];
Its better to use UIGestureRecogizers for basic gestures like double tap:
UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleDoubleTap:)];
doubleTapGestureRecognizer.numberOfTapsRequired = 2;
[self.scrollView addGestureRecognizer:doubleTapGestureRecognizer];
and in your handleDoubleTap:
function you can call whatever method you want.
It looks like bigImageView is stretching to fit scrollView when it's added to it. SO, your method is not getting called because you are really tapping on bigImageView, not scrollView.
精彩评论