如何在iPhone上使用CALayer? [英] How do I use CALayer with the iPhone?

查看:154
本文介绍了如何在iPhone上使用CALayer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有一个UIView子类,它在屏幕上标记一个2px×2px CGLayerRef,最多160 x 240次。

Currently, I have a UIView subclass that "stamps" a single 2px by 2px CGLayerRef across the screen, up to 160 x 240 times.

我目前正在为此设置动画通过将UIView向上移动屏幕2个像素(实际上是UIImageView),然后绘制下一个行。

I currently animate this by moving the UIView "up" the screen 2 pixels (actually, a UIImageView) and then drawing the next "row".

使用多个CALayer层会加快性能渲染这个动画?

Would using multiple CALayer layers speed up performance of rendering this animation?

是否有教程,示例应用程序或代码片段用于使用iPhone SDK的CALayer?

Are there tutorials, sample applications or code snippets for use of CALayer with the iPhone SDK?

我问的原因是我发现的大多数代码片段都演示了CALayer使用方法调用的简单示例,这些代码调用不适用于iPhone SDK。我很感激任何建议或指示。

The reason I ask is that most of the code snippets I find that demonstrate simple examples of CALayer employ method calls that do not work with the iPhone SDK. I appreciate any advice or pointers.

推荐答案

好吧,好吧,如果你想要一些有很好的CA好例子的话这样的事情并在手机上工作,我推荐 Jens Aflke发布的GeekGameBoard 代码(它是某些Apple演示代码的改进版)。

Okay, well, if you want something that has some good examples of CA good that draws things like that and works on the phone, I recommend the GeekGameBoard code that Jens Aflke published (it is an improved version of some Apple demo code).

根据您所描述的内容,我认为您正在做某种方式比它需要的更复杂。我的印象是你基本上想要一个静态视图,你通过改变它的位置来动画,以便它部分偏离屏幕。如果你只需要在drawRect中设置一些静态内容,那么通过图层调用CGFillRect()并不会比用你的颜色更快。之后,你可以在UIView上使用隐式动画和动画师代理来移动视图。我怀疑你甚至可以摆脱定制的drawRect:带有图案UIColor的实现,但老实说我没有对两者之间的差异进行基准测试。

Based on what you are describing I think you are doing somthing way more complicated than it needs be. My impression is you want basically a static view that you are animating by shifting its position so that it is partially off screen. If you just need to set some static content in your drawRect going through layers is not going to be faster than just calling CGFillRect() with your color. After that you could just use implicit animations and the animator proxy on UIView to move the view. I suspect you could even get rid of the custom drawRect: implementation with a patterned UIColor, but I honestly have not benchmarked the difference between the two.

这篇关于如何在iPhone上使用CALayer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆