在iOS中双击图像不放大
Posted
技术标签:
【中文标题】在iOS中双击图像不放大【英文标题】:Image not Zoom On double tap in iOS 【发布时间】:2015-09-04 12:25:38 【问题描述】:在我的具有画廊功能的应用程序中。对于滚动图像,我使用了 REPagedScrollView,我想使用 2 根手指在捏合时缩放图像,并且还想在双击时缩放,但我无法在双倍上缩放图像轻敲 请解决我的问题。 我试过下面的代码:
.h 文件
@interface ViewPhotoVC : UIViewController<UIScrollViewDelegate,UIGestureRecognizerDelegate>
REPagedScrollView *scrollView;
UIScrollView *image_scroll;
int current_page;
BOOL is_FullScreen;
@property (strong,nonatomic) IBOutlet UIView *slider_view;
.m 文件
-(void)video_image_Gallery
scrollView = [[REPagedScrollView alloc] initWithFrame:self.slider_view.bounds];
scrollView.delegate=self;
// scrollView.pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
// scrollView.pageControl.currentPageIndicatorTintColor = [UIColor grayColor];
current_page=0;
for(int i=0;i<[self.PhotoImgArr count];i++)
self.image_view = [[AsyncImageView alloc] initWithFrame:CGRectMake(0,0, self.slider_view.frame.size.width, self.slider_view.frame.size.height)];
// scrollView.frame=CGRectMake(0, 0, screenwidth, screenheight);
image_scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,screenwidth,screenheight)];
self.image_view.backgroundColor=[UIColor clearColor];
self.image_view.contentMode = UIViewContentModeScaleAspectFit;
self.image_view.clipsToBounds = true;
self.image_view.userInteractionEnabled = YES;
self.image_view.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);
self.image_view.image = [UIImage imageNamed:@"no_image1.png"];
self.image_view.imageURL =[NSURL URLWithString:[self.PhotoImgArr objectAtIndex:i]];
self.image_view.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:246.0/255.0 blue:241.0/255.0 alpha:1];
[image_scroll setDelegate:self];
[image_scroll setShowsHorizontalScrollIndicator:NO];
[image_scroll setShowsVerticalScrollIndicator:NO];
[image_scroll setMaximumZoomScale:8.0];
image_scroll.tag=i+1;
self.PlayVideoBtn.tag=i+1;
self.image_view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
image_scroll.contentSize = CGSizeMake(self.image_view.bounds.size.width-500, self.image_view.bounds.size.height-300);
image_scroll.decelerationRate = UIScrollViewDecelerationRateFast;
// [image_scroll setMinimumZoomScale:[image_scroll frame].size.width / [self.image_view frame].size.width];
[image_scroll setZoomScale:[image_scroll minimumZoomScale]];
[image_scroll addSubview:self.image_view];
[image_scroll addSubview:self.PlayVideoBtn];
[image_scroll addSubview:self.videoImg];
scrollView.tag=0;
// self.PlayVideoBtn.tag=0;
[scrollView addPage:image_scroll];
[self.slider_view addSubview:scrollView];
self.index_lbl.text = [NSString stringWithFormat:@"%d of %lu",(int)self.selected_index+1,(unsigned long)[self.PhotoImgArr count]];
[scrollView scrollToPageWithIndex:self.selected_index animated:YES];
- (void)scrollViewDidScroll:(UIScrollView *)scrollView1
if(scrollView1.tag ==0)
CGFloat pageWidth = scrollView1.frame.size.width;
current_page = floor((scrollView1.contentOffset.x - pageWidth / 2.0) / pageWidth) + 1;
self.index_lbl.text = [NSString stringWithFormat:@"%d of %lu",current_page+1,(unsigned long)[self.PhotoImgArr count]];
if(current_page+1==self.PhotoImgArr.count)
self.nextBtn.userInteractionEnabled=NO;
self.nextImg.image=[UIImage imageNamed:@"disable_next.png"];
else if(current_page==0)
self.prevBtn.userInteractionEnabled=NO;
self.prevImg.image=[UIImage imageNamed:@"disable_prev.png"];
else
self.nextBtn.userInteractionEnabled=YES;
self.prevBtn.userInteractionEnabled=YES;
self.nextImg.image=[UIImage imageNamed:@"next.png"];
self.prevImg.image=[UIImage imageNamed:@"prev.png"];
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView1
if([self.PhotoOrVideo isEqualToString:@"Photo"])
if([[scrollView1 viewWithTag:scrollView1.tag].subviews count]>0)
return [[scrollView1 viewWithTag:scrollView1.tag].subviews objectAtIndex:0];
return nil;
【问题讨论】:
@SaurabhJain 我解决了这个问题。这是旧帖子。 【参考方案1】:请尝试以下代码:
-(void)setScrollView:(UIScrollView *)scrollView
_scrollView=scrollView;
_scrollView.minimumZoomScale=0.2;
_scrollView.maximumZoomScale=3.0;
_scrollView.delegate=self;
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
return self.imageView;
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
[self.scrollView flashScrollIndicators];
【讨论】:
以上是关于在iOS中双击图像不放大的主要内容,如果未能解决你的问题,请参考以下文章