2015-09-07 45 views
1

在我的應用程序中,使用了庫概念。這需要雙擊縮放圖像並使用2個手指。 我使用下面的代碼,但它不適合我。我啓用實現此功能.. 請解決我的問題。如何縮放雙擊圖像並在iOS中用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

的可能重複userInteractionEnabled [如何放大/縮小的UIImage的對象時,用戶捏屏幕?](http://stackoverflow.com/questions/500027 /如何縮放出一個uiimage對象時,用戶捏屏) –

+0

你給的鏈接這個方法scaleAndRotateImage不叫 –

回答

0

你應該設置的image_scroll

image_scroll.userInteractionEnabled = YES; 
+0

仍然不工作 –

+0

調試,它進入' - (void)handleDoubleTap :(UIGestureRecognizer *)gestureRecognizer'? – anhtu