开发者

iOS zoom algorithm

开发者 https://www.devze.com 2023-04-06 05:11 出处:网络
I am creating a graphing calculator applica开发者_如何学Gotion in OpenGL on iOS, and I would like to implement pinch zooming that works like the google maps application or uiscrollview zooming. I\'m p

I am creating a graphing calculator applica开发者_如何学Gotion in OpenGL on iOS, and I would like to implement pinch zooming that works like the google maps application or uiscrollview zooming. I'm pretty sure I can't use a uiscrollview because the content of the graph is being generated dynamically.

Implementing zooming where the center of the screen is assumed to be the center of the zoom is easy, but in other cases it is not obvious to me how its being implemented. Can anyone point me in the right direction?


The view that does your custom drawing should be capable of drawing at a certain scale. When your user zooms in or out of the scroll view, send the appropriate zoom factor and let the view redraw itself. The changing bounds is not a problem. The scroll view adjusts its bounds as you pan inside, so its subviews shouldn't have any concern over the bounds of the scroll view.

Of course, you'll probably have to consider performance. For example, it may be too slow to redraw the graph at every frame as a user zooms. Instead, you may only want to redraw when the user stops zooming, which is what Maps.app does.

There are many other considerations for this problem, but that would be where I would start.

EDIT: Ah, I overlooked the OpenGL aspect. Still, with a GL layer-backed view, you still should be able to make the appropriate translations based on both the current zoom factor as well as the scroll view's bounds.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号