How do I use CALayer with the iPhone?

后端 未结 3 1696
余生分开走
余生分开走 2021-02-10 18:05

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

I currently animate this by moving the UIVie

3条回答
  •  没有蜡笔的小新
    2021-02-10 18:30

    What CALayer methods are you seeing that don't work on iPhone? Aside from animation features tied to CoreImage I have not noticed much that is missing. The big thing you are likely to notice is that all views are layer backed (so you do not need to do anything special to use layers, you can just grab a UIView's layer through the layer accessors methos), and the coordinate system has a top left origin.

    In any event, generally having more things is slower than having fewer things. If you are just repeating the same pattern over and over again you are likely to find the best performance is implementing a custom UIView/CALayer/UIColor that knows how to draw what you want, rather than placing visually identical layers or views next to each other.

    Having said that, generally layers are lighter weight than views, so if you have a lot of separate elements that you need to keep logically separated you will find that moving to layers can be a win over using views.

    You might want to look at -[UIColor initWithPatternImage:] depending on exactly what you are trying to do. If you are using this two pixel pattern as a background color you could just make a UIColor that draws it and set the background.

提交回复
热议问题