Everyone knows that you cannot trust the size of a frame in the init / viewDidLoad method of the UIViewController; this is:
- (void)viewDidLoad: { NSLog(@"%d", self.view.frame.size.width); }
will print the wrong sizes in many cases (in particular, it is badly broken in landscape mode)
This will return always corrected results, so it's nice to post subview layouts:
- (void)viewWillAppear: { NSLog(@"%d", self.view.frame.size.width); }
The problem is that viewWillAppears is called every time the view appears, so it is not suitable for posting or adding subviews. This way you end up declaring each view in the interface, and you end up with huge header files that I donβt like at all, since most elements no longer need to be manipulated after the initial setup.
So, the first question: Is there a better way to handle positioning routines?
Question two is very related, let's say I have a subclass of UIView, including various other subclauses. I declare it inside my interface, and I select / initialize it in the init / viewDidLoad method.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { ... menu = [[SNKSlidingMenu alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); ... }
As we already know, now we need to move it to viewWillAppear to get a more accurate reading.
- (void)viewWillAppear:(BOOL)animated{ .... menu.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); .... }
The problem is that, of course, all sub-views also need to be moved. This is done using the layoutSubviews function, which is called automatically, but we have the same problem: All subqueries must be declared inside the interface of the SNKSlidingMenu class. Is there any way around this?
Thanks.