在我的应用程序中,使用了库概念。这需要双击并使用2个手指来放大图像。 我使用下面的代码,但它不适合我。我能够实现这个功能.. 请解决我的问题。
- (void)viewDidLoad
{
[self setupScrollView];
}
-(void) setupScrollView
{
//add the scrollview to the view
image_scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,
self.view.frame.size.width,
self.view.frame.size.height)];
image_scroll.pagingEnabled = YES;
[image_scroll setAlwaysBounceVertical:NO];
//setup internal views
for (int i = 0; i < [self.PhotoImgArr count]; i++) {
current_page =(int)self.PhotoImgArr[i];
CGFloat xOrigin = i * self.view.frame.size.width;
AsyncImageView *image = [[AsyncImageView alloc] initWithFrame:
CGRectMake(xOrigin, 0,
self.view.frame.size.width,
self.view.frame.size.height)];
image.imageURL = [NSURL URLWithString:self.PhotoImgArr[i]];
image.contentMode = UIViewContentModeScaleAspectFit;
[image_scroll addSubview:image];
}
//set the scroll view content size
[image_scroll setShowsHorizontalScrollIndicator:NO];
[image_scroll setShowsVerticalScrollIndicator:NO];
[image_scroll setMaximumZoomScale:8.0];
self.image_view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
image_scroll.decelerationRate = UIScrollViewDecelerationRateFast;
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[image_scroll addGestureRecognizer:doubleTap];
image_scroll.contentSize = CGSizeMake(self.view.frame.size.width *
self.PhotoImgArr.count,
self.view.frame.size.height);
//add the scrollview to this view
[self.view addSubview:image_scroll];
[image_scroll setZoomScale:[image_scroll minimumZoomScale]];
}
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {
if(image_scroll.zoomScale > image_scroll.minimumZoomScale)
[image_scroll setZoomScale:image_scroll.minimumZoomScale animated:YES];
else
[image_scroll setZoomScale:image_scroll.maximumZoomScale animated:YES];
}
答案 0 :(得分:0)
您应该设置userInteractionEnabled
image_scroll
image_scroll.userInteractionEnabled = YES;