UIView and calayer

0

I'm learning about Core Animation, and from what I understood about CALayer and UIView is the layer of view is responsible for drawing the same since it uses the gpu and not the cpu, so its performance is more effective. Until now, I understood well?

Now my doubt, the properties of the layer can come to do the same as the properties of the view? That is, if I modify my layer I am modifying my view or just the layer? Example: If I use view.frame would be the same as view.layer.position and view.layer.bounds ? (Position would be the left point and above, and bounds would take care of the size)

    
asked by MatiEzelQ 13.01.2017 в 20:57
source

1 answer

1

A UIView is a wrap around a CALayer, adding event handling and gestures, for example. You can create a CALayer without UIView but not a UIView without CALayer.

Therefore, when you modify a property in the view, what you are doing is actually modifying the layer.

For example:

let view = UIView()

view.frame = CGRect(x: 0, y: 0, width: 50, height: 50) // Esto es lo mismo que
view.layer.frame = CGRect(x: 0, y: 0, width: 50, height: 50) //que esto

view.alpha = 0 //O esto 
view.layer.opacity = 0 //a esto

That yes, all the properties of the layer are not exposed in the UIView, as for example the cornerRadius or the anchorPoint.

If you want to go deeper into the beautiful world of Core Animation I advise you this book:

iOS Core Animation: Advanced Techniques - Amazon

    
answered by 16.01.2017 в 19:21