iOS controls hide and gone like android

后端 未结 4 1600
没有蜡笔的小新
没有蜡笔的小新 2021-01-04 09:05

I have used storyboard with autolayout for my UI design. Basically in android there are three different properties will be there like Visible, Invis

4条回答
  •  清歌不尽
    2021-01-04 09:42

    Neither removing the subview, nor adjusting the frame worked for me, so as an alternate solution, I programmatically added a constraint that automatically adjusts the difference.

    For example: If you have 3 views, A_view B_view and C_view vertically aligned in that order and you want to "Hide" B and also adjust the difference, add a constraint

    B_view.removeFromSuperView()
    var constr = NSLayoutConstraint(item: C_view, 
                                    attribute: NSLayoutAttribute.Top, 
                                    relatedBy: NSLayoutRelation.Equal, 
                                    toItem: A_view, 
                                    attribute: NSLayoutAttribute.Bottom,
                                    multiplier: 1,
                                    constant: 20)
    view.addConstraint(constr)
    

    constant is (in this case) the amount of vertical space between C_view and A_view

    It worked for me, but requires knowledge of constraints

提交回复
热议问题