Search code examples
iosios7autolayoutios-autolayout

Autolayout detect when UIView got the frame


I have UIView that has auto layout constraints. I create it with frame CGRectZero. So I don't the real size. It will depend on superview.

But I want to know when my view get a frame that I can use for my calculation.


Solution

  • So you shouldn't really need to know anything about the frame. Although if you did need to know, you could just implement -layoutSubviews in your view, or -viewDidLayoutSubviews at the view controller level.

    Here after calling super the frames should be set to what AutoLayout resolved them to be.

    Also good practise to take on board is #7 of the following post: Forget frame.

    I also highly recommend reading about the AutoLayout process here.