I'm trying to learn how to use autolayout and write constraints using the visual format language. for a simple test I have a test view and want it to expand the full size. So top, bottom, trailing, leading to superview would all be zero.
If I run in iOS 7, it seems to mostly work, but get black bars on the top and bottom of iPhone 5 simulator with no ambiguous layout errors.
In iOS 8, I get ambiguous layout errors. Can anyone show me where my problem is?
Here's my code:
- (void)viewDidLoad {
[super viewDidLoad];
testView = [UIView new];
testView.backgroundColor = [UIColor blueColor];
testView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:testView];
[self.view needsUpdateConstraints];
}
- (void)updateViewConstraints
{
[super updateViewConstraints];
[self.view removeConstraints:self.view.constraints];
NSDictionary *viewsDictionary =
NSDictionaryOfVariableBindings(testView);
NSArray *constraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"|[testView]|"
options:0
metrics:nil
views:viewsDictionary];
[self.view addConstraints:constraints];
constraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"V:|[testView]|"
options:0
metrics:nil
views:viewsDictionary];
[self.view addConstraints:constraints];
}
Thanks!
-- Update - the issue seems to be with [self.view removeConstraints:self.view.constraints]; If I comment that out, it works fine. Not sure why though.