Closed Sun3 closed 10 years ago
Hi, sorry I forgot to make the demo app universal. Thanks for reminding. Now it works on iPad.
Also added instructions to the readme. Let me know if you still have issues.
evgenyneum
That worked great thank you.
I have another item I was trying to handle. Let's say I am in portrait mode and I zoon into the image then I rotate to landscape, is there a way to keep the image zoomed in?
Great control... thanks.
ps: I added below code to add the feature to double tap to zoom in and double tap again to zoom out. Please feel free to add it to your control if you like
' @property (readwrite, nonatomic) CGFloat maximumScale;
(void) viewWillAppear:(BOOL)animated { // CURRENT CODE HERE
// Initialize Maximum Scale self.maximumScale = self.scrollView.zoomScale * 2;
// Add Double Tap Zoom/Zoom Out UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)]; [doubleTap setNumberOfTapsRequired:2]; [self.scrollView addGestureRecognizer:doubleTap]; }
(void)handleDoubleTap:(UIGestureRecognizer )gestureRecognizer { // zoom in float newScale = 0; if (self.scrollView.zoomScale < self.maximumScale) { newScale = [self.scrollView zoomScale] \ ZOOM_STEP; } else { newScale = [self.scrollView zoomScale] / ZOOM_STEP; }
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]]; [self.scrollView zoomToRect:zoomRect animated:YES]; }
(CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center {
CGRect zoomRect;
// Zoom in or out depending on newScale zoomRect.size.height = [self.scrollView frame].size.height / scale; zoomRect.size.width = [self.scrollView frame].size.width / scale;
// Center. zoomRect.origin.x = center.x - (zoomRect.size.width / 2.0); zoomRect.origin.y = center.y - (zoomRect.size.height / 2.0);
return zoomRect; } '
@Sun3, if you want to keep zoom level on orientation change please look at updateZoom
method where it sets zoomScale
.
I would leave this demo without double tap. The main purpose of this repo is to show the basics of using scroll view and image with auto layout. I did not intend to build full-featured control for dealing with images. If you want to do that - feel free to fork this repo or create one from scratch.
@evgenyneu thanks...
@Sun3 thank you for your feedback. Let me know how it goes with your image control.
I am using it great for iPhone screens but when I placed the same code in an iPad Storyboard the Image does not zoom well, very choppy. Also when view loads you can move around the image without zooming.
Any ideas?
Thanks for a great control.