在运行时快速更改约束

2023-09-09移动开发问题
3

本文介绍了在运行时快速更改约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 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
}

这篇关于在运行时快速更改约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在 cocos2d 中添加 UIViewController
Add UIViewController in cocos2d(在 cocos2d 中添加 UIViewController)...
2024-08-12 移动开发问题
4

UIScrollView 和 Cocos2D
UIScrollView and Cocos2D(UIScrollView 和 Cocos2D)...
2024-08-12 移动开发问题
2

如何在 UIView 上添加 CCSprite
How to add CCSprite over UIView(如何在 UIView 上添加 CCSprite)...
2024-08-12 移动开发问题
5

如何在 cocos2d 中以编程方式创建新的 UIView?
How to create a new UIView programmatically in cocos2d?(如何在 cocos2d 中以编程方式创建新的 UIView?)...
2024-08-11 移动开发问题
5

对 <GKModalRootViewController: 0xb7e450> 的开始/结束
Unbalanced calls to begin/end appearance transitions for lt;GKModalRootViewController: 0xb7e450gt;(对 lt;GKModalRootViewController: 0xb7e450gt; 的开始/结束外观转换的不平衡调用)...
2024-08-11 移动开发问题
5

CCDirecter 用 UIView/nib 替换场景
CCDirecter replace scene with UIView / nib(CCDirecter 用 UIView/nib 替换场景)...
2024-08-11 移动开发问题
3