我正在开发与 iOS8 和 iOS7 兼容的应用程序。
我通过子类化制作了一个集合视图标题,UICollectionReusableView
并且 UI 是使用 Interface Builder 制作的。这是标头接口的架构:
----------------------------
| |
| A |
| |
|---------------------------|
| |
| B |
| |
|---------------------------|
| |
| C |
| |
----------------------------
问题
A
,B
并且C
视图通过超级视图 ( UICollectionReusableView
) 上的前导和尾随链接,并且在 iOS8 上运行良好。但是在iOS7上,当视图布局为具有参考大小(宽度为 768pt)时,子视图的宽度为 1216pt(它应该与父视图的宽度相同:768pt)...
我发现了什么
以下是对 的约束UICollectionReusableView
:
<NSLayoutConstraint:0x7c4196c0 UIView:A.top == HEADER:0x7be52ff0.top>,
<NSLayoutConstraint:0x7c4196f0 HEADER:0x7be52ff0.trailing == UIView:A.trailing>,
<NSLayoutConstraint:0x7c419720 UIView:A.leading == HEADER:0x7be52ff0.leading>,
<NSLayoutConstraint:0x7c4197b0 HEADER:0x7be52ff0.trailing == UIView:B.trailing>,
<NSLayoutConstraint:0x7c419810 UIView:B.top == UIView:A.bottom>,
<NSLayoutConstraint:0x7c419840 UIView:B.leading == HEADER:0x7be52ff0.leading>,
<NSLayoutConstraint:0x7c419870 UIView:C.top == UIView:B.bottom>,
<NSLayoutConstraint:0x7c4198a0 UIView:C.leading == HEADER:0x7be52ff0.leading>,
<NSLayoutConstraint:0x7c4198d0 HEADER:0x7be52ff0.trailing == UIView:C.trailing>,
<NSLayoutConstraint:0x7c419900 HEADER:0x7be52ff0.bottom == UIView:C.bottom>,
<NSLayoutConstraint:0x7be98df0 HEADER:0x7be52ff0.width == 768>,
<NSLayoutConstraint:0x7be98e20 HEADER:0x7be52ff0.height == 512>
这是通过在控制台中调用in layoutSubviews
my时发生的情况:UICollectionReusableView
[self recursiveDescription]
打电话之前[super layoutSubviews]
<HEADER: 0x7be52ff0; baseClass = UICollectionReusableView; frame = (0 0; 768 512); clipsToBounds = YES; layer = <CALayer: 0x7be87300>>
| <UIView: A; frame = (0 0; 320 360); autoresize = RM+BM; layer = <CALayer: 0x7be53190>>
| | ...
| <UIView: B; frame = (0 360; 320 96); autoresize = RM+BM; layer = <CALayer: 0x7be6bc50>>
| | ...
| <UIView: C; frame = (0 456; 320 56); autoresize = RM+BM; layer = <CALayer: 0x7c417360>>
| | ...
打电话后[super layoutSubviews]
<HEADER: 0x7be52ff0; baseClass = UICollectionReusableView; frame = (0 0; 768 512); clipsToBounds = YES; layer = <CALayer: 0x7be87300>>
| <UIView: A; frame = (0 0; 1216 360); autoresize = RM+BM; layer = <CALayer: 0x7be53190>>
| | ...
| <UIView: B; frame = (0 360; 1216 96); autoresize = RM+BM; layer = <CALayer: 0x7be6bc50>>
| | ...
| <UIView: C; frame = (0 456; 1216 56); autoresize = RM+BM; layer = <CALayer: 0x7c417360>>
| | ...
尝试
我试图设置前导和尾随常量相对于边距,这没有帮助。
我还尝试手动更改 的框架A
,B
并C
在调用[super layoutSubviews]
和调用setNeedLayout
这些视图之后。但正如我所料,它会使应用程序崩溃。
问题
我很难找到为什么会发生这种情况,因为里面有子视图A
,B
并且C
视图并没有试图扩展他们的超级视图。
是否有一些调试技术可以帮助我确定此错误的来源?
感谢您的帮助 !