I am new to Auto Layout in iOS. I really like the concept in principle, but it's driving me nuts trying to get the simplest things done. I suspect I'm still missing some simple underlying principle. I am trying to learn by doing and get the basics right before actually working with it in an app, so I'm creating very simple test projects. Here's one as simple as it gets that doesn't work as expected. First the part that works. In IB, I add a View to fill the entire viewcontroller, and XCode automatically sets the constraints to Top/Bottom/Leading/Trailing and the Space to 0. When done with IB, it works as expected:
rotates to

Great!
Now I am trying to do the same thing in code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *redView = [[UIView alloc] initWithFrame:self.view.bounds];
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
redView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0f constant:0.0f]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1.0f constant:0.0f]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0f constant:0.0f]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1.0f constant:0.0f]];
}
That's all the code there is other than the default code for a Single-view application.
When I run the above code, trying to mirror the same thing as I get with IB programmatically, I get this after rotation:

How come that the same constraints lead to different results? It's probably something really simple and embarrassingly stupid that I am missing. Help!!!