Hide autolayout UIView : How to get existing NSLayoutConstraint to update this one

后端 未结 2 1419
故里飘歌
故里飘歌 2020-11-30 11:35

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 solu

相关标签:
2条回答
  • 2020-11-30 11:55

    UIView has a method that returns all constraints affecting its layout in one of the dimensions:

    NSArray *constraints = 
    [someView constraintsAffectingLayoutForAxis:UILayoutConstraintAxisVertical];
    

    Then you can just find the one you're interested in.

    0 讨论(0)
  • 2020-11-30 12:04

    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];
    

    enter image description here

    Or just do it to hide an UIView with autolayout:

    //Hide View 
    [myView1 setConstraintConstant:0 forAttribute:NSLayoutAttributeHeight];
    
    0 讨论(0)
提交回复
热议问题