CGContext Optimization

烂漫一生 提交于 2019-12-06 14:37:45

Drawing a 1,000-point or 10,000-point path 60 times per second is really going to slow your application down, if it's possible at all. If the path is static, you really should look at only drawing it once within your UIView, so that it is cached within the UIView's layer, and animating the layer around. It it needs to be animated, you could look at the new CAShapeLayer, which provides the ability to animate a Bezier path simply by applying an animation to its path property.

However, 10,000 pixels will be wider than the maximum texture size on the iPhone (2048 x 2048), so you'll have problems displaying that in any standard view or layer and may need to either break it up into smaller chunks or use a CATiledLayer to render it to the screen.

After trying a lot of things (like dividing my huge 1000 points path into smaller 10 points paths etc...), I've ported everything to openGL, using simple vertex arrays. It took me about 4 hours to port everything (even scaling the path, scrolling it, etc...) and now, I get a full 60fps animation all the time, when I was having only 22fps average with peaks at 28 when using the CoreGraphics.

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