iOS: Autolayout with child view controllers -


i've been using autolayout couple of weeks now. currently, i'm using 3rd party library called flkautolayout makes process easier. i'm @ point can construct views way want, without problem. however, on past 4 days @ work i've been struggling autolayout once viewcontrollers involved. i'm fine sorts of uiviews... reason, every viewcontroller.view total demon. i've had nothing problems getting viewcontroller.view size way want , ever deeper problem uiviews of child viewcontrollers not receive events when using autolayout. child viewcontrollers work fine when designating frames manually, breaks down autolayout.

i don't understand what's different viewcontroller's uiview makes different others... mind melting in frustration. ios messing viewcontroller views behind scenes or something?

sample image http://i39.tinypic.com/6qeh3r.png

in image, red area belongs child view controller. area should not going past bottom subview (the card says three). should easy , can work fine bunch of normal uiviews because viewcontroller, breaks...

can shed light on don't know. leads on potential issues appreciated.

thanks reading.

update: problem may related ambiguous constraints

uiview *box = [[uiview alloc]init]; [box addsubview:imageview]; [box addsubview:namelabel];  imageview constrainwidth:@"32" height:@"32"]; [imageview aligntop:@">=0" leading:@"0" bottom:@"<=0" trailing:@"<=0" toview:box]; [imageview aligncenterywithview:box predicate:@"0"];  [namelabel constrainleadingspacetoview:imageview predicate:@"5"]; [namelabel aligntop:@">=0" leading:@">=0" bottom:@"<=0" trailing:@"<=0" toview:box]; [namelabel aligncenterywithview:box predicate:@"0"];  [self addsubview:box]; [box aligntop:@"5" leading:@"5" bottom:@"-5" trailing:@"-5" toview:self]; 

the example above ambiguous layout can't figure out what's wrong it...

this should comment, comments suck code. ;-)


did check ambiguous constraints? me view looks can caused ambiguous constraints.

add code app delegate:

// before @implementation appdelegate @interface uiwindow (autolayoutdebug) + (uiwindow *)keywindow; - (nsstring *)_autolayouttrace; @end  // inside of @implementation  - (void)motionbegan:(uieventsubtype)motion withevent:(uievent *)event {     nsstring *autolayouttrace = [[uiwindow keywindow] _autolayouttrace];     if ([autolayouttrace rangeofstring:@"ambiguous"].location != nsnotfound) {         nslog(@"%@", autolayouttrace);     }     else {         nslog(@"no ambiguous autolayout found");     } } 

and shake simulator. you'll find shake gesture in hardware menu.

if doesn't show "no ambiguous autolayout found" check ambiguous ui element(s) in trace printed. marked "ambiguous".

then start add constraints there no more ambiguity.

you can call exerciseambiguityinlayout on ui-element has ambiguous layout hint constraints missing.


and make sure remove debugging code in shipping product. might put 2 parts inside of #if debug , #endif


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -