Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CALayer内部没有属性的疑问 #10

Open
TheWalkingDead1024 opened this issue Sep 1, 2016 · 1 comment
Open

CALayer内部没有属性的疑问 #10

TheWalkingDead1024 opened this issue Sep 1, 2016 · 1 comment

Comments

@TheWalkingDead1024
Copy link

对象的调整也经常是消耗 CPU 资源的地方。这里特别说一下 CALayer:CALayer 内部并没有属性,当调用属性方法时,它内部是通过运行时 resolveInstanceMethod 为对象临时添加一个方法,并把对应属性值保存到内部的一个 Dictionary 里,同时还会通知 delegate、创建动画等等,非常消耗资源。UIView 的关于显示相关的属性(比如 frame/bounds/transform)等实际上都是 CALayer 属性映射来的,所以对 UIView 的这些属性进行调整时,消耗的资源要远大于一般的属性。对此你在应用中,应该尽量减少不必要的属性修改。

CALayer是出于什么目的,内部没有属性,而去动态解析呢,这样有什么优势吗?还望大神指点。

@ibireme
Copy link
Owner

ibireme commented Sep 1, 2016

CALayer 需要动画啊,看看 CAAction 和动画相关的那些方法。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants