I have a uiscrollview and inside it there is a uiimageview. I want to be used to be able to enlarge the image due to the large image. scrollview only needs to scroll vertically, not horizontally.
before adding the scaling effect, I had the following code, and it worked the way I wanted,
-(void)viewDidLoad
{
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 1690)];
}
So, I did some research and got the following code to turn scaling on and off.
-(void)viewDidLoad
{
scrollView.scrollEnabled = YES;
[scrollView setContentSize:CGSizeMake(320, 1690)];
scrollView.delegate = self;
scrollView.minimumZoomScale = scrollView.frame.size.width / instImage.frame.size.width;
scrollView.maximumZoomScale = 2.0;
[scrollView setZoomScale:scrollView.minimumZoomScale];
[[NSRunLoop currentRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate distantFuture]];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return instImage;
}
- (CGRect)centeredFrameForScrollView:(UIScrollView *)scroll andUIView:(UIView *)rView {
CGSize boundsSize = scroll.bounds.size;
CGRect frameToCenter = rView.frame;
if (frameToCenter.size.width < boundsSize.width) {
frameToCenter.origin.x = ((boundsSize.width - frameToCenter.size.width) / 2);
}else {
frameToCenter.origin.x = 0;
}
return frameToCenter;
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollV {
instImage.frame = [self centeredFrameForScrollView:scrollV andUIView:instImage];;
}
Now I have the following problems, and I can’t understand what happened,
.
qaru.site/questions/1103634/...
, NSDefaultRunLoopMode , , .