2015-09-04 55 views
1

在我的應用程序具有畫廊功能。對於滾動圖像我使用REPagedScrollView,我想圖像縮放使用2個手指捏,也想縮放雙擊,但我無法放大雙擊圖片 請解決我的問題。 我試圖通過下面的代碼:圖像不縮放在iOS雙擊

.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; 
} 
+0

@SaurabhJain我解決了這個問題。這是舊帖子。 –

回答

0

請嘗試下面的代碼:

-(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]; 
}