隐藏自动版式的UIView:如何让现有的NSLayoutConstraint更新这一项 [英] Hide autolayout UIView : How to get existing NSLayoutConstraint to update this one
问题描述
我知道如何修改现有的约束。但我想知道是否有人已经找到了解决方案,得到了约束,而无需保存这一个作为一个属性。
目前的解决方案来设置约束高度:
1)保存在NSLayoutConstraint一个变量:
NSLayoutConstraint * heightConstraint = [NSLayoutConstraint constraintWithItem:MyView的
属性:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:无
属性:NSLayoutAttributeNotAnAttribute
事半功倍:1.0F
常数:20];
[self.view addConstraint:heightConstraint];
2)设置保存到0.0(隐藏这种观点的约束的常数)
[heightConstraint setConstant:200];
我在寻找这样一个解决方案:
[MyView的setConstraint:@0。 forAttribute:NSLayoutAttributeHeight]
我刚刚建立了这个类别(<一个href=\"https://github.com/damienromito/UIView-UpdateAutoLayoutConstraints\">https://github.com/damienromito/UIView-UpdateAutoLayoutConstraints)当您希望该更新限制:
//你可以使用工具来隐藏/显示一个UIView
[myView1 hideByHeight:YES];
或只是做,以隐藏与自动布局的UIView的:
//隐藏查看
[myView1 setConstraintConstant:0 forAttribute:NSLayoutAttributeHeight];
I know how to modify a existing constraint. But I would to know if someone has found a solution to get a constraint without save this one as a property.
Current solution to set Constraint height:
1) save NSLayoutConstraint in a variable:
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:myView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0f
constant:20];
[self.view addConstraint:heightConstraint];
2) Set the constant of the Constraint saved to "0.0" ( to hide this view)
[heightConstraint setConstant:200];
I'm looking for a solution like this:
[myView setConstraint:@"0." forAttribute:NSLayoutAttributeHeight]
I just built this Category (https://github.com/damienromito/UIView-UpdateAutoLayoutConstraints) that update constrains when you want:
//you can use tools to hide/show a uiview
[myView1 hideByHeight:YES];
Or just do it to hide an UIView with autolayout:
//Hide View
[myView1 setConstraintConstant:0 forAttribute:NSLayoutAttributeHeight];
这篇关于隐藏自动版式的UIView:如何让现有的NSLayoutConstraint更新这一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!