斯威夫特在运行时更改的限制 [英] changing constraints at runtime in swift

查看:108
本文介绍了斯威夫特在运行时更改的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的iOS中的约束部分非常薄弱。我经历了许多参考链接了如下图所示,但仍然没能解决我的问题。

I'm really very weak in constraints part of ios. I have gone through many reference link as shown below but still not able solve my issue.

<一个href=\"http://stackoverflow.com/questions/22384927/hide-autolayout-uiview-how-to-get-existing-nslayoutconstraint-to-update-this-o/\">Hide自动版式的UIView:如何让现有的NSLayoutConstraint来更新这个

在的情况下,我需要改变基于某些条件UIView2的y轴。该storyboard.png示出的布局。

In case , i need to change the y-axis of UIView2 based on some condition. The storyboard.png shows the layout.

如果条件与步骤1失败UIView2,第二步第三步和应该是可见,它的位置也应该在condition1.png变化如图所示

If condition fails UIView2 with step1, step 2 and step3 should be visible and it's position should also change as shown in condition1.png

在这里输入的形象描述

如果条件通过UIView2与步骤1,步骤2和步骤3的应该是不可见的如图condition1.png

If condition pass UIView2 with step1, step 2 and step3 should not be visible as shown in condition1.png

在这里输入的形象描述

请给我提供了如何实现上述场景的步骤。我尝试了做什么,但如果设置为UIView1约束的高度保持不变,在运行时不会发生改变。

Please provide me steps for how to achieve the above scenario. I tried it doing but if set the constraint for UIView1 the height remains same and does not change at runtime.

推荐答案

只是让双方的UIView的高度,出口和使用常量属性来更改像...

just make the outlet of height of both UIView and use constant property to change the height constraints like...

if conditionfails{
     heightconstOfView1.constant = 0
}
else{
    heightconstOfView2.constant = 0
}

修改

示范项目

这篇关于斯威夫特在运行时更改的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆