1

In my application , used gallery concept. And this want to Zoom Image with double tap and using 2 finger. I used below code for this but its not working for me. i enable to achieve this functionality.. Please resolve my problem.

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

    }
Monika Patel
  • 2,287
  • 3
  • 20
  • 45
  • possible duplicate of [How to zoom in/out an UIImage object when user pinches screen?](http://stackoverflow.com/questions/500027/how-to-zoom-in-out-an-uiimage-object-when-user-pinches-screen) – Anbu.Karthik Sep 07 '15 at 05:05
  • your given link this method scaleAndRotateImage not called – Monika Patel Sep 07 '15 at 05:14

1 Answers1

0

You should set userInteractionEnabled of image_scroll

image_scroll.userInteractionEnabled = YES;
tuledev
  • 10,177
  • 4
  • 29
  • 49