iOS 大小 类,未安装的视图和插座
iOS Size Classes, Uninstalled Views and Outlets
我有一个 UILabel 出口。对于任意宽度和任意高度,标签为 "installed",但对于紧凑宽度和任意高度,标签为 "uninstalled"。
当我使用 iPhone 5 模拟器(紧凑宽度,任意高度)运行 这个项目时,我仍然可以看到有效的插座。为什么是这样?它不应该是 nil 还是什么?我还认为它是有效的但只是隐藏了(我看不到出口,但 isHidden 是假的)。它会发生什么?
我错过了什么?
提前致谢!
来自Apple's Size Classes Design Help
A runtime object for an uninstalled view is still created. However,
the view and any related constraints are not added to the view
hierarchy and the view has a superview property of nil. This is
different from being hidden. A hidden view is in the view hierarchy
along as are any related constraints.
如果您查看已卸载 UILabel
的 superView
属性,您会发现它是 nil
。
如果插座本身为零,则在尝试访问它时可能会遇到问题;您的代码必须明确检查活动大小 class 并调整其行为。通过仍然创建对象但不将其添加到视图层次结构,您的代码仍然可以对标签进行操作,只是这些操作不会产生任何可见的效果。
我有一个 UILabel 出口。对于任意宽度和任意高度,标签为 "installed",但对于紧凑宽度和任意高度,标签为 "uninstalled"。
当我使用 iPhone 5 模拟器(紧凑宽度,任意高度)运行 这个项目时,我仍然可以看到有效的插座。为什么是这样?它不应该是 nil 还是什么?我还认为它是有效的但只是隐藏了(我看不到出口,但 isHidden 是假的)。它会发生什么?
我错过了什么?
提前致谢!
来自Apple's Size Classes Design Help
A runtime object for an uninstalled view is still created. However, the view and any related constraints are not added to the view hierarchy and the view has a superview property of nil. This is different from being hidden. A hidden view is in the view hierarchy along as are any related constraints.
如果您查看已卸载 UILabel
的 superView
属性,您会发现它是 nil
。
如果插座本身为零,则在尝试访问它时可能会遇到问题;您的代码必须明确检查活动大小 class 并调整其行为。通过仍然创建对象但不将其添加到视图层次结构,您的代码仍然可以对标签进行操作,只是这些操作不会产生任何可见的效果。