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
}
这篇关于在运行时快速更改约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在运行时快速更改约束
基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01