0

Want to understand exact difference between masking any layer and adding a layer as sublayer. I have searched and found some answers but not able to understand it correctly.

Something I found like masking causes offscreen rendering but adding a sublayer doesn't so can't we just use addsublayer?

Here I found something but not getting this so if there is any example of this would help more


More specific : Lets have a layer say layer1 now I want to understand difference between following :

  • addSublayer(layer1)
  • mask = layer1

We know here that both are applied using main layer of our UIView like view.layer

2 Answers2

0

Layer - is a "next view on super view", but sublayer is a "next layer on super layer". Hierarhy: View(Super) -> has view(super) -> has layers(super): [layer1, layer2, etc] -> layer1(super) -> has sublayers(super) [sublayer1, sublayer2, etc]. sublayers - endpoint in hierarhy.

a view can have more layers. layer can have more sublayers. but sublayer cant have other sublayers.

// sorry for my english :)

ZaurGiyasov
  • 126
  • 6
0

If I understand this correctly, the layer is added on top of the view whereas the mask is a subtraction of the current layer.

If you have a gradient layer add it to the view it will follow the gradient direction specified lets say from the bottom to top. But if you add the same gradient as a mask, you would be subtracting the layer and therefore it would like the gradient comes from the top to the bottom. Also you can use masks to cut shapes in images. They are very similar though.

Gustavo Baiocchi Costa
  • 1,379
  • 3
  • 16
  • 34