What you're seeing is exactly how a mask is supposed to work. You are applying the mask to the layer of the superview. Let's call that view superview
(just as in your code). Okay, so what will that do? It will mask superview
and all its sublayers. That includes its subviews. Its subviews are actually its sublayers.
So, since the buttons are subviews of superview
, they are masked like everything else inside superview
.
If you don't want that to happen, don't make the buttons subviews of superview
. They can sit on top of superview
without being its subviews, for example.