changing constraints at runtime in swift(在运行时快速更改约束)
问题描述
我在 ios 的约束部分方面真的很弱.我浏览了许多参考链接,如下所示,但仍然无法解决我的问题.
如果条件在第 1 步时 UIView2 失败,第 2 步和第 3 步 应该可见,并且它的位置也应该改变,如 condition1.png 所示
如果条件通过 UIView2 与 step1,则 step 2 和 step3 应该不可见 如 condition1.png 所示
请提供如何实现上述场景的步骤.我试过这样做,但如果为 UIView1 设置约束,高度保持不变并且在运行时不会改变.
只要把两个UIView的高度做出口,用常量属性来改变高度约束,比如...
如果条件失败{heightconstOfView1.constant = 0}别的{heightconstOfView2.constant = 0}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.
Hide autolayout UIView : How to get existing NSLayoutConstraint to update this one
In case , i need to change the y-axis of UIView2 based on some condition. The storyboard.png shows the layout.
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
If condition pass UIView2 with step1, step 2 and step3 should not be visible as shown in condition1.png
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.
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
}
这篇关于在运行时快速更改约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在运行时快速更改约束
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
