updateViewConstraints seems to be called too early. If I launch the app in landscape on iPad, I initially get portrait constraints until I rotate.
viewWillAppear: ...if I do it, no dice. Too early?
viewDidAppear: if I do it..... the constraints update...but it's nasty, because the view already appeared. also stuck it in viewWillLayoutSubviews...before the call to super. If I launch the app in landscape I still get portrait only constraints until viewDidAppear.
-(void)doUpdateConstraints
{
if (self.view.frame.size.width < self.view.frame.size.height)
{
//in portrait...disable landscape traits first...otherwise autolayout may throw
for (NSLayoutConstraint *constraint in self.landscapeConstraints) {constraint.active = NO; }
for (NSLayoutConstraint *constraint in self.portraitConstraints) { constraint.active = YES; }
}
else
{
//in landscape...disable portrait first...otherwise autolayout may throw.
for (NSLayoutConstraint *constraint in self.portraitConstraints) { constraint.active = NO; }
for (NSLayoutConstraint *constraint in self.landscapeConstraints) { constraint.active = YES; }
}
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self doUpdateConstraints];
}
-(void)updateViewConstraints
{
[super updateViewConstraints];
[self doUpdateConstraints];
}