Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewWillLayoutSubviews is getting called way too much

In my viewController.view, I have some work done in viewWillLayoutSubviews that organizes which subviews are visible, which to bring to the front, which to hide, etc, if the orientation changes.

But I have buttons on my view that somehow cause viewWillLayoutSubviews to get called every time they are pressed. Why would this be? According to the Apple docs, viewWillLayoutSubviews is only called if your view's bounds change.

The result is that my views are getting re-arranged just from pressing a button, but I'm not rotating the device at all nor am I manipulating view.bounds or view.frame in any way.

like image 479
johnbakers Avatar asked Sep 14 '12 05:09

johnbakers


People also ask

Why is viewDidLayoutSubviews called multiple times?

Meaning the method viewDidLayoutSubviews is called every time the view size changes and the view layout has been recalculated.

How do I contact viewWillLayoutSubviews?

The viewWillLayoutSubviews() method is also called after the view is resized and positioned by its parent. If a view controller is not visible when an orientation change occurs, then the rotation methods are never called. However, the viewWillLayoutSubviews() method is called when the view becomes visible.

What is viewDidLayoutSubviews?

viewDidLayoutSubviews()Called to notify the view controller that its view has just laid out its subviews.


1 Answers

You better do one thing andrews take a bool and set it TRUE on button press and check it on layoutSubviews and operate whether it is true or false. You get it what i am trying to do.

like image 74
Deepak Avatar answered Sep 27 '22 18:09

Deepak