samedi 20 septembre 2014

Force multiplier to update on Interface Builder constraint


Vote count:

0




I've created a height constraint for a UIView in the Interface Builder that sets the height to = the superview. I set the multiplier to 1/3 of the superview's width. This works great, it sets the height, say on iPhone 5/5S, to ~107pts.


For wider screens, I want to set the multiplier to 1/4 instead; I suppose I could do this with Size Classes, but I'm not sure that's the best way to go for this?


In my viewWillAppear method of a view controller, I've tried doing the following; no matter what I do though, it still sets the height to only ~107pts. Note that _controlsAspectRatio is an IBOutlet to the IB constraint.



_controlsAspectRatio = [NSLayoutConstraint constraintWithItem:_controlsAspectRatio.firstItem attribute:_controlsAspectRatio.firstAttribute relatedBy:_controlsAspectRatio.relation toItem:_controlsAspectRatio.secondItem attribute:_controlsAspectRatio.secondAttribute multiplier:1.0f/4.0f constant:0];

[_controlsContainer setNeedsUpdateConstraints];
[_controlsContainer setNeedsLayout];
[_controlsContainer layoutIfNeeded];
NSLog(@"%0.4f - %0.4f", _controlsContainer.frame.size.height, _controlsAspectRatio.multiplier);

// Output: 106.6667 - 0


asked 1 min ago

remus

6,603






Force multiplier to update on Interface Builder constraint

Aucun commentaire:

Enregistrer un commentaire