Tuesday 15 July 2014

ios - Create view hierarchy programmatically with Auto Layout -



ios - Create view hierarchy programmatically with Auto Layout -

i want create view hierarchy programmatically using auto layout hierarchy has next structure: uiview -> uiwebview want leave space uitoolbar @ bottom of uiview.

the result should in xib file:

code 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 trace using:

po [[uiwindow keywindow] _autolayouttrace]

i both uiview , uiwebview have ambiguous layout.

what problem approach?

you shouldn't set translatesautoresizingmaskintoconstraints no controller's self.view. if remove line, constraints have should adequate. btw, there's no need zeros in format string (although don't wound either),

this "h:|[webview]|" equivalent "h:|-0-[webview]-0-|".

ios objective-c autolayout

No comments:

Post a Comment