Dam*_*ito 11 objective-c show-hide uiview autolayout nslayoutconstraint
我知道如何修改现有约束.但我想知道是否有人找到了一个解决方案来获得一个约束而不保存这个属性.
当前设置约束高度的解决方案:
1)将NSLayoutConstraint保存在变量中:
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:myView
                                                                    attribute:NSLayoutAttributeHeight
                                                                    relatedBy:NSLayoutRelationEqual
                                                                       toItem:nil
                                                                    attribute:NSLayoutAttributeNotAnAttribute
                                                                   multiplier:1.0f
                                                                     constant:20];
[self.view addConstraint:heightConstraint];
2)将约束的常量设置为"0.0"(隐藏此视图)
[heightConstraint setConstant:200];
我正在寻找这样的解决方案:
 [myView setConstraint:@"0." forAttribute:NSLayoutAttributeHeight]
Dam*_*ito 14
我刚建立了这个类别(https://github.com/damienromito/UIView-UpdateAutoLayoutConstraints),可以根据需要更新约束:
//you can use tools to hide/show a uiview
[myView1 hideByHeight:YES];

或者只是用autolayout隐藏UIView:
//Hide View 
[myView1 setConstraintConstant:0 forAttribute:NSLayoutAttributeHeight];
UIView有一个方法可以在其中一个维度中返回影响其布局的所有约束:
NSArray *constraints = 
[someView constraintsAffectingLayoutForAxis:UILayoutConstraintAxisVertical];
然后你就可以找到你感兴趣的那个.
| 归档时间: | 
 | 
| 查看次数: | 17169 次 | 
| 最近记录: |