Step 1 : In .h file add ui-image-view object as ==>> IBOutlet UIImageView *imgView;
imgView object use to set image to zoom in /out
Step 2: No need to set UIScrollView object in .h / .m file, just set the delegate to file's owner from storyboard(Interface builder).
Step 3: set the zoom level of your image at scroll view:
Go-to Interface builder select UIScrollView , choose code inspector then set zoom : min & max
set min = 0.5; 50% zoom level and max = 8; 800% zoom level
If min = 0 , it meaning no lower limit is set and zoom out to infinite level ( which is not recommended).
step 4: add this lines to .m file; UIScrollView delegates for zoom functionality
imgView object use to set image to zoom in /out
Step 2: No need to set UIScrollView object in .h / .m file, just set the delegate to file's owner from storyboard(Interface builder).
Step 3: set the zoom level of your image at scroll view:
Go-to Interface builder select UIScrollView , choose code inspector then set zoom : min & max
set min = 0.5; 50% zoom level and max = 8; 800% zoom level
If min = 0 , it meaning no lower limit is set and zoom out to infinite level ( which is not recommended).
step 4: add this lines to .m file; UIScrollView delegates for zoom functionality
#pragma mark - Scroll View Delegate //Object to zoom; in this case imgView - (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView1{ return imgView; } // method use to set imgView at center of scrollView - (void)scrollViewDidZoom:(UIScrollView *)scrollView1 { UIView *subView = [scrollView1.subviews objectAtIndex:0]; CGFloat offsetX = MAX((scrollView1.bounds.size.width - scrollView1.contentSize.width) * 0.5, 0.0); CGFloat offsetY = MAX((scrollView1.bounds.size.height - scrollView1.contentSize.height) * 0.5, 0.0); subView.center = CGPointMake(scrollView1.contentSize.width * 0.5 + offsetX, scrollView1.contentSize.height * 0.5 + offsetY); }
No comments:
Post a Comment