What happens with constraints when a view is removed(删除视图时约束会发生什么)
问题描述
我的问题很简单,但我在文档中找不到任何信息.
The question I have is simple but I couldn't find any information in the documentation.
当视图从视图层次结构中移除(或移动到另一个视图)时,布局约束会发生什么情况?
What happens with layout constraints when a view is removed from the view hierarchy (or moved to another view)?
例如,让我们有容器 C 与子视图 A 和 B.容器 C 包含一些约束.然后我们调用 [A removeFromSuperview].A 的约束会发生什么?
For example, let's have container C with subviews A and B. Container C holds some constraints. Then we call [A removeFromSuperview]. What happens with the constraints for A?
如果我们再次将 A 添加到 C 会发生什么?
What then happens if we add A to C again?
推荐答案
约束被移除.如果再次添加 A,则必须为其创建新的约束,或者如果在删除 A 之前保存约束,则可以重新添加它们.当我做这样的事情时,我会为一个名为 view1 的视图保存这样的约束:
The constraints are removed. If you add A again, you will have to make new constraints for it, or if you save the constraints before you remove A, you can add them back. When I do something like this, I save the constraints like this for a view called view1:
self.portraitConstraints = [NSMutableArray new];
for (NSLayoutConstraint *con in self.view.constraints) {
if (con.firstItem == self.view1 || con.secondItem == self.view1) {
[self.portraitConstraints addObject:con];
}
}
这篇关于删除视图时约束会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:删除视图时约束会发生什么
基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
