隐藏自动布局 UIView:如何让现有的 NSLayoutConstraint 更新这个 [英] Hide autolayout UIView : How to get existing NSLayoutConstraint to update this one
本文介绍了隐藏自动布局 UIView:如何让现有的 NSLayoutConstraint 更新这个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何修改现有约束.但是我想知道是否有人找到了一种解决方案来获得约束而不将此作为属性保存.
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) 将 NSLayoutConstraint 保存在一个变量中:
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:myView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0f
constant:20];
[self.view addConstraint:heightConstraint];
2) 将保存的 Constraint 的常量设置为0.0"(隐藏此视图)
[heightConstraint setConstant:200];
<小时>
我正在寻找这样的解决方案:
[myView setConstraint:@"0." forAttribute:NSLayoutAttributeHeight]
推荐答案
我刚刚建立了这个类别 (https://github.com/damienromito/UIView-UpdateAutoLayoutConstraints) 在需要时更新约束:
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];
或者只是这样做来隐藏带有自动布局的 UIView:
Or just do it to hide an UIView with autolayout:
//Hide View
[myView1 setConstraintConstant:0 forAttribute:NSLayoutAttributeHeight];
这篇关于隐藏自动布局 UIView:如何让现有的 NSLayoutConstraint 更新这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文