LayoutSubviews called twice during rotation

When my main view rotates, I want to re-arrange the sub-views, so in my ViewController I redefine

willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration 

and set the framework to a subspecies. This is all good and good, but in subViews I also redefined

  layoutSubviews 

so that they appear correctly. But the problem is that now it is called twice - presumably once when I set Frame to willAnimateRotationToInterfaceOrientation and once because of rotation. (If I do not install Frame, it will be called once.)

Undoubtedly, the responsibility of the ViewController is to compose frames so that it looks like a design flaw - what is the solution, so that layoutSubviews is called only once?

+6
source share
1 answer

I had the same question. I found this page to be useful to me. Is this helpful to you?

EDIT: Here is a brief description of the page (copied):

  • init does not call layoutSubviews (duh)
  • addSubview causes display of layoutSubviews in the added view, the view of its addition in (target view) and all subzones of the target view
  • setFrame intelligently calls layoutSubviews in a view that has its frame only if the frame size parameter is different
  • scrolling UIScrollView causes display layoutSubviews to scrollView and its supervisor
  • A device rotation only causes a layoutSubview on the parent view (the main view of the responding viewControllers)
  • removeFromSuperview - layoutSubviews is called only for the supervisor (does not appear in the table)
+17
source

All Articles