0
votes

I am drawing a graph where the graph scales on zooming in. The graph view is the contentView of scrollview. I also have a graph axis view placed just under the graphview (having same width) which is a regular UIView but I manage the positioning of labels on this view myself according to the zoom scale and panning. I found that my label positioning were not syncing with the graph content correctly (while zooming). I redraw the content after zooming ends.

Apple docs say that zooming occurs around the visible content

Zooming Programmatically
Now if the visible content is same as the size of the frame, the contentView center should not move, but I found in the -(void)scrollViewDidZoom:(UIScrollView *)scrollview method by NSloging the contentView center that it moves in +ve x(to the right)slightly as I zoom-in more and more. I expected it to remain stationary.Is it a bug or am I missing something ?

PS: I understand that if the size of contentView is less than the visible bounds of scrollview, the center will drift to the left (towards origin).

1
I have noticed that behavior when zooming out, less than the bounds of the scroll view. But for your main problem, can you provide more details/context? Any sample code? I'd imagine that pinching out would adjust bot the zoom and the content offset as the touches are triggering both a UIPinch- and UIPan- gesture recognizer. - Ryan

1 Answers

0
votes

I also posted the question in apple dev forums and I got the right response which makes sense.

Here it is:
Remember, center is derived from 0x X 0y, not from bounds proper. When zooming, you can hit one bound before you hit the other, so any reference to them would freeze center when one is maxed out. If zoom is calculated off top left/right you'll see the center from them instead regardless

This means center is recalculated from Top left (0,0) (I also verified this).

CGPoint newCentre = CGPointMake(oldCentre.x*scale, oldCentre.y*scale);

and that is the reason it drifts forward a little bit