привет, у меня есть несколько изображений в uiscrollview. на самом деле я хочу реализовать прокрутку изображения, как в iphone image gallary. я загружаю изображения с url на imagearray, тогда я могу успешно отображать и прокручивать эти изображения из imagearray в uiscrollview. но моя проблема заключается в том, что я хочу включить двойное нажатие увеличения/уменьшения и два нажатия пальцем в/из в uiscrollviiew, как в iphone gallary. например, при двойном нажатии пользователя изображение будет увеличиваться. и когда пользователь снова дважды коснется этого изображения, изображение будет увеличиваться. а также в том же случае с двумя жесты. я попытался выполнить его чтение учебников, но can not удалось на самом деле проблема заключается в том, когда я дважды коснувшись метода изображения Doubletap изображения, который называется succcessfully, но может влиять на размер изображения, это код, который я использовал для прокрутки и распознавания жестов. для распознавания жестов я использовал код, один из сайта яблочногоКак увеличить двойное нажатие зума и увеличить изображение с двумя пальцами uiimage в uiscrollview
if (imagesArray.count < 1)
{
msgView = [[UIView alloc]initWithFrame:CGRectMake(35, 190, 250, 40)];
[msgView setBackgroundColor:[UIColor blackColor]];
[msgView setAlpha:0.5];
UILabel *mgtLbl = [[UILabel alloc]initWithFrame:CGRectMake(25, 8, 250, 25)];
[mgtLbl setText:@"Sorry no image available for this post"];
[mgtLbl setFont:[UIFont systemFontOfSize:13.0]];
[mgtLbl setBackgroundColor:[UIColor clearColor]];
[mgtLbl setTextColor:[UIColor blueColor]];
[msgView addSubview:mgtLbl];
[self.view addSubview:msgView];
}
else {
[msgView removeFromSuperview];
[self.view setBackgroundColor:[UIColor blackColor]];
srcVw = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
srcVw.scrollEnabled = YES;
srcVw.delegate = self;
[srcVw setZoomScale:1.0];
srcVw.showsHorizontalScrollIndicator = YES;
srcVw.showsVerticalScrollIndicator = NO;
srcVw.pagingEnabled = NO;
//add the scrollview to the view
srcVw = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height)];
srcVw.pagingEnabled = YES;
[srcVw setAlwaysBounceVertical:NO];
//setup internal views
NSInteger numberOfViews = imagesArray.count;
for (int i = 0; i < numberOfViews; i++) {
CGFloat xOrigin = i * self.view.frame.size.width;
image = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0,self.view.frame.size.width,400)];
/*
[image setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat: @"http://www.junkremoval.co.uk/bedspace/%@",[imagesArray objectAtIndex:i]]]];
*/
image.image = [imagesArray objectAtIndex:i];
image.contentMode = UIViewContentModeScaleAspectFit;
// image.frame = (CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=image.image.size};
[srcVw addSubview:image];
}
//set the scroll view content size
srcVw.contentSize = CGSizeMake(self.view.frame.size.width *numberOfViews,
self.view.frame.size.height);
[self.view addSubview:srcVw];
[image setTag:ZOOM_VIEW_TAG];
[image setUserInteractionEnabled:YES];
// add gesture recognizers to the image view
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];
[doubleTap setNumberOfTapsRequired:2];
[twoFingerTap setNumberOfTouchesRequired:2];
[image addGestureRecognizer:singleTap];
[image addGestureRecognizer:doubleTap];
[image addGestureRecognizer:twoFingerTap];
// calculate minimum scale to perfectly fit image width, and begin at that scale
float minimumScale = [srcVw frame].size.width/[image frame].size.width;
[srcVw setMinimumZoomScale:minimumScale];
[srcVw setZoomScale:minimumScale];
}
/************************************** NOTE **************************************/
/* The following delegate method works around a known bug in zoomToRect:animated: */
/* In the next release after 3.0 this workaround will no longer be necessary */
/**********************************************************************************/
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
[scrollView setZoomScale:scale+0.01 animated:NO];
[scrollView setZoomScale:scale animated:NO];
}
#pragma mark TapDetectingImageViewDelegate methods
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
// single tap does nothing for now
}
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {
// double tap zooms in
float newScale = [srcVw zoomScale] * ZOOM_STEP;
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
[srcVw zoomToRect:zoomRect animated:YES];
}
- (void)handleTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer {
// two-finger tap zooms out
float newScale = [srcVw zoomScale]/ZOOM_STEP;
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
[srcVw zoomToRect:zoomRect animated:YES];
}
#pragma mark Utility methods
- (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center {
CGRect zoomRect;
// the zoom rect is in the content view's coordinates.
// At a zoom scale of 1.0, it would be the size of the imageScrollView's bounds.
// As the zoom scale decreases, so more content is visible, the size of the rect grows.
zoomRect.size.height = [srcVw frame].size.height/scale;
zoomRect.size.width = [srcVw frame].size.width/scale;
// choose an origin so as to get the right center.
zoomRect.origin.x = center.x - (zoomRect.size.width/2.0);
zoomRect.origin.y = center.y - (zoomRect.size.height/2.0);
return zoomRect;
}
http://www.c-sharpcorner.com/UploadFile/d49768/image-zooming-in-iphone/ – Rajneesh071
http://stackoverflow.com/questions/9008975/how-to-tap-to-zoom-and-double-tap-to-zoom-out-in-ios/9009554#9009554 –