I\'m creating a custom on / off toggle switch for the iPhone (similar to the standard switch) and i\'m at the point where I\'m setting the mask of the slider, but calling
A mask is just a special kind of sublayer, so the superlayer of the mask will always be the layer it's masking. There is no way around it. Also, you are violating this warning in the documentation:
When setting the mask to a new layer, the new layer’s superlayer must first be set to nil, otherwise the behavior is undefined.
You should remove the [[self layer] addSublayer:maskLayer];
line.
To solve your problem, I would create another layer or view that contains everything that is now on your toggleView and then add that layer to your toggleLayer as a sublayer. That way, you can position the new sublayer independently of the mask and if you move the parent layer, both the mask and the sublayer will move together (which is what they should do if I understand you correctly).