use*_*641 5 objective-c ios ios7 ios8
我在UICollectionViewCell中使用autolayout.超级简单的布局:只是一个UILabel.我希望UILabel占据整个宽度减去20像素的插入,并在垂直和水平方向上居中.我设置了那样做的约束.如果我在任何ios 8设备或模拟器上运行它,它可以很好地工作.但是,当我在某些ios 7设备上运行时,约束无效.我试着浏览一下苹果文档,但他们的改动似乎都不是围绕自动布局.
这是XML源代码,但我怀疑它意味着什么:
<constraints>
<constraint firstItem="OIc-cg-9hO" firstAttribute="leading" secondItem="Ga6-nx-lOn" secondAttribute="leading" constant="20" id="A7U-sd-fcL"/>
<constraint firstAttribute="centerY" secondItem="OIc-cg-9hO" secondAttribute="centerY" id="G9e-9W-aDS"/>
<constraint firstAttribute="centerX" secondItem="OIc-cg-9hO" secondAttribute="centerX" id="TrB-hI-7Kw"/>
<constraint firstAttribute="trailing" secondItem="OIc-cg-9hO" secondAttribute="trailing" constant="20" id="yjH-nf-D9U"/>
</constraints>
Run Code Online (Sandbox Code Playgroud)
更多的解决方法而不是答案:但我在代码中添加了约束,如下所示:
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeWidth
multiplier:1.0
constant:-20.0]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0.0]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0.0]];
Run Code Online (Sandbox Code Playgroud)
为了使它工作,我需要编码约束和IB约束.不知道为什么!
小智 5
听起来您的Interface Builder约束使用了iOS7不支持的"约束到边距"选项.打开IB中的约束并检查其中是否有任何项目选中了"相对于保证金"选项.
见什么是"约束保证金",在故事板在Xcode 6和什么是"约束保证金",在故事板在Xcode 6上的约束更多细节保证金.
小智 4
这发生在我身上,你必须检查 UI 中的每个约束并删除 iOS 8 中引入的相对于边距的约束,并且不支持 iOS 7,不要忘记那些你可能会忘记的地方(例如 UITableView 单元格) )。
要找到此选项:
点击 UI 控件
转到尺寸检查器
双击任何约束并检查边距,如果有任何变化,只需将其关闭并修复约束即可。

| 归档时间: |
|
| 查看次数: |
3185 次 |
| 最近记录: |