Search code examples
iosuiviewcalayer

How to prevent layoutSubviews being called when transforming sublayers?


I have some Layer1 attached to the root layer of my custom view as sublayer.

And then this funny thing happens that when I have changed the transform of Layer1 inside touchesMoved, layoutSubviews is called.

I know there are all kinds of way to bypass this. But what's the logic behind it? Can it be prevented, instead of that I need find walk arounds?


Solution

  • Unfortunately, it doesn't seem to be preventable.

    My usual solution is to add another view to the hierarchy in between the parent and the child. The new view essentially works as a dummy container and does nothing on its layoutSubviews.