Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

layoutSubviews being called repeatedly on ios6 after CATransaction

I inherited an overly complicated project (so I don't know all of the inner workings), and I'm running into a bug. Certain parts of my app have some long animations done with CATransaction, and it seems to be causing layoutSubviews to be called repeatedly while the animations are active. This doesn't happen on ios5 and everything looks correct, but on ios6 it gets called nonstop and interferes with a lot of the layout of the view. The stack trace is all hidden/grayed out, but it does seem to begin with CA::Transaction::commit()

Did anything with CATransaction change between ios versions to cause something like this?

like image 635
Chris C Avatar asked Nov 30 '12 19:11

Chris C


1 Answers

See this post: UIView/CALayer: Transform triggers layoutSubviews in superview

Apple answered me via TSI:

why am I seeing this behavior? is this inconsistency or am I misunderstanding some core concepts?

A view will be flagged for layout whenever the system feels something has changed that requires the view to re-calculate the frames of its subviews. This may occur more often than you'd expect and exactly when the system chooses to flag a view as requiring layout is an implementation detail.

why does it cascade upwards the view hierarchy?

Generally, changing a geometric property of a view (or layer) will trigger a cascade of layout invalidations up the view hierarchy because parent views may have Auto Layout constraints involving the modified child. Note that Auto Layout is active in some form regardless of whether you have explicitly enabled it.

how can I avoid superview to layoutSubviews every time I'm changing transform?

There is no way to bypass this behavior. It's part of UIKit's internal bookkeeping that is required to keep the view hierarchy consistent.

like image 86
hfossli Avatar answered Sep 29 '22 12:09

hfossli