Unable to set frame correctly before viewDidAppear

后端 未结 3 1412
悲&欢浪女
悲&欢浪女 2020-11-30 22:45

I was wondering if anyone knows why when you set the frame of a subview in viewDidLoad and viewWillAppear the changes do not take affect on the scr

3条回答
  •  抹茶落季
    2020-11-30 23:12

    See this thread When is layoutSubviews called?
    When use autolayout, framework do not call layoutSubviews automatically. That is very important. From ref:

    • init does not cause layoutSubviews to be called (duh)
    • addSubview: causes layoutSubviews to be called on the view being added, the view it’s being added to (target view), and all the subviews of the target. ...


    If you add subview in viewDidLoad, layoutSubviews called before viewDidAppear, and you can get the correct size of subviews. But if you do nothing, layoutSubviews will be called after viewDidAppear. It's up to your code.

提交回复
热议问题