问题
In UIScrollview, when I scroll/drag, I got changes in scrollview contentOffset which represent how much I had scrolled/dragged in the scrollview. By this way, I have updated the subview of scrollview for scrolling.
But, when I zoom the scrollview (using pinch zooming), the contentOffsets of the scrollview is also changed. I do not understand how much contentOffset has changed because I can not relate the changes with zoomScale value. So, is there anyway to know changes in contentOffset for zooming?
My intention is get the value of contentOffset changes for dragging while zooming (which is not I am getting because of zooming content offset changes) so that I can update my scrollview's subview accordingly.
I am stuck in here. Any help will be very much appreciated.
thanks
Shaikot
回答1:
I've set up a small test project, and it looks like the contentOffset is multiplied by the zoomScale
. So if you want to account for that, just divide it by the zoomScale
before using it.
Maybe it's best to illustrate with a small example: I've set up a scrollView, and added a view that's big enough to pan around and zoom a bit. To that view, I've added a small red view that I want to keep in the same position, no matter what. I'm observing the contentOffset property of the scrollView, and I've implemented it like this:
CGPoint contentOffset = self.scrollView.contentOffset;
CGFloat zoomScale = self.scrollView.zoomScale;
self.moveView.frame = CGRectMake((contentOffset.x+10)/zoomScale,
(contentOffset.y+10)/zoomScale,
10,
10);
This keeps the moveView in the same position on the screen, only scaling it when the user zooms.
I hope this clears thing up a bit, but let me know if I can do more to help.
来源:https://stackoverflow.com/questions/3051361/how-much-contentoffset-changes-in-uiscrollview-for-zooming