How much contentOffset changes in UIScrollview for zooming?

守給你的承諾、 提交于 2019-12-04 13:03:02

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!