I’m having a problem with the zoomToRect function. I have a scroll view that contains views. When the user clicks on an view, I launch a zoom into it. It’s working except that when the y position of the frame is higher than 2389, the function zoom to the corresponding frame at 2389 y position.
Here is the code I use :
-(void) launchZoomInAnimationInView:(UIView*) cellView; {
// Get the rect corresponding to the clicked cell
CGRect zoomedFrame = [self.zoomScrollView convertRect:cellView.frame fromView:cellView.superview];
// Zoom to the rect
[self.zoomScrollView zoomToRect:zoomedFrame animated:YES];
// Display for debugging
[ViewToolkit showFrame:zoomedFrame inView:self.zoomScrollView];
NSLog (@"Zoom on frame %@ with contentSize %f", NSStringFromCGRect(zoomedFrame), self.zoomScrollView.contentSize.height);
}
The function showframe shows me that the frame I calculated is at a correct position (I display a red rectangle on screen).
The NSLog shows that the content size is high enough :
Zoom on frame {{100, 3021.6}, {230.4, 307.2}} with contentSize 10337.759766.
At the end of the animation, I display the bounds of the scrollView and it gives me {{100, 2389}, {768, 1024}}, instead of {{100, 3021.6}, {768, 1024}}
I really don’t get it. For any value above 2389 I always get a ending frame with 2389 y position. And this value doesn’t change when the contentSize is different.
Note that before launching this function, I didn’t change the zoomScale of the scrollView.
The problem was due to my viewForZoomingInScrollView function which was returning the scrollview itself while it’s supposed to return the child of the scrollView.
See the full answer here : https://devforums.apple.com/message/406487
According to the discussion on Apple forum, it seems there is a bug in Apple API so we should NEVER return the scrollView in viewForZoomingInScrollView.