I can scroll the image view, but pinch to zoom in/out does not work. Where went wrong?
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
UIImageView *imageView = [[UIImageView alloc] init];
[self.scrollView addSubview:imageView];
imageView.frame = CGRectMake(0, 0, chosenImage.size.width, chosenImage.size.height);
imageView.image = chosenImage;
self.scrollView.maximumZoomScale = 4;
self.scrollView.minimumZoomScale = 0.1;
self.scrollView.showsVerticalScrollIndicator=YES;
self.scrollView.delegate = self;
self.scrollView.scrollEnabled=YES;
self.scrollView.userInteractionEnabled=YES;
self.scrollView.contentSize = CGSizeMake(chosenImage.size.width, chosenImage.size.height);
[picker dismissViewControllerAnimated:YES completion:NULL];
}
The first of all make sure your views have the correct delegates implemented. For example in the .m file
@interface myViewController () <UIGestureRecognizerDelegate, UIScrollViewDelegate>
The UIScrollView class can have a delegate that must adopt the UIScrollViewDelegate protocol. For zooming and panning to work, the delegate must implement both viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale:; in addition, the maximum (maximumZoomScale) and minimum ( minimumZoomScale) zoom scale must be different.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.fullScreenView;
}
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.