Reputation: 285
I want to create a view hierarchy programmatically using Auto Layout The hierarchy has the following structure: UIView -> UIWebView I want to leave some space for a UIToolbar at the bottom of the UIView.
The result should be as in this xib file:
Code so far:
- (void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.view = view;
self.webView = [[UIWebView alloc] init];
self.webView.scalesPageToFit = YES;
[self.view addSubview:self.webView];
self.view.translatesAutoresizingMaskIntoConstraints = NO;
self.webView.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *nameMap = @{@"webView" : self.webView};
NSArray *c1Array =
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[webView]-0-|"
options:0
metrics:nil
views:nameMap];
NSArray *c2Array =
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[webView]-45-|"
options:0
metrics:nil
views:nameMap];
[self.view addConstraints:c1Array];
[self.view addConstraints:c2Array];
}
When I trace using:
po [[UIWindow keyWindow] _autolayoutTrace]
I get that both UIView and UIWebView have ambiguous layout.
What could be the problem with my approach?
Upvotes: 0
Views: 444
Reputation: 104082
You shouldn't set translatesAutoresizingMaskIntoConstraints to NO for the controller's self.view. If you remove that line, the constraints you have should be adequate. BTW, there's no need for the zeros in your format string (although they don't hurt either),
this "H:|[webView]|"
is equivalent to this "H:|-0-[webView]-0-|"
.
Upvotes: 1