Layout issues in iOS10

516 Views Asked by At

I'll try to keep this short. I was using viewDidLayoutSubviews to (mostly) apply corner radius to some views in several UIViewControllers. Also doing the same in layoutSubviews for custom UIViews.

After installing Xcode 8 Beta, this stopped behaving predictably. Some times it works, others works with a delay, others still, not at all...

The one thing that was immediate while debugging was that on first call of viewDidLayoutSubviews, bounds are zero for the views in question. On second call, the bounds are correct; the thing is, as I said, the second call either has a (visible) delay, or never happens at all.

Any pointers? Thank you all in advance.

Best, Renato.

1

There are 1 best solutions below

3
On BEST ANSWER

Answering my own question, just in case someone bumps into the same issue...

As far as I can tell, in iOS 10 you cannot assume calls performed on layoutSubviews, viewDidLayoutSubviews, etc. will be called on the main thread.

So the answer seems to be simply wrapping the UI calls on a dispatch block (new iOS 10 sintax):

DispatchQueue.main.async {
        // Do UI stuff here...
        }

Hope it is helpful for someone :)

Best regards,

Renato.