Reputation:
I'm using the following code in viewDidLoad method. I'm expecting the image to be zoomed when it is pinched but it is not getting zoomed.
[self.displayImage setUserInteractionEnabled:YES];
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:@"imageUrl"];
NSLog(@"saved %@",savedValue);
_displayImage.image = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {
NSData *data0 = [NSData dataWithContentsOfURL: [NSURL URLWithString:savedValue]];
UIImage *image = [UIImage imageWithData: data0];
dispatch_sync(dispatch_get_main_queue(), ^(void) {
_displayImage.image = image;
});
});
self.displayReceivedImageScrollView.delegate = self;
[self.displayReceivedImageScrollView addSubview:_displayImage];
_displayReceivedImageScrollView.contentSize = _displayImage.frame.size;
_displayReceivedImageScrollView.scrollEnabled = YES;
// For supporting zoom,
_displayReceivedImageScrollView.minimumZoomScale = 0.5;
_displayReceivedImageScrollView.maximumZoomScale = 2.0;
self.displayReceivedImageScrollView.contentOffset = CGPointMake(self.displayReceivedImageScrollView.bounds.size.width, 0);
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToLeftWithGestureRecognizer:)];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToRightWithGestureRecognizer:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self.displayImage addGestureRecognizer:swipeLeft];
[self.displayImage addGestureRecognizer:swipeRight];
I have added the imageview in storyboard. But I'm inflating the scrollview during runtime so as to enable zooming. I'm not be able to zoom it. swipeLeft or swipeRight method is never getting called. How can I sort this out?
Upvotes: 0
Views: 64
Reputation: 1698
For Zoom the image you can use the scroll View Delegate method:
-(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];
}
Upvotes: 1