什么会导致以下警告(以及iOS 7上的后续对齐问题)?
属性不可用:相对于8.0之前的iOS版本上的布局边距的布局属性
首先,我有3个不同的UIViews来替换iPad故事板上的Split View Controller中的细节视图
它在iOS8 iPad上运行良好.但是当我加载其中一个细节视图时,应用程序在iOS7和iOS 6 Simulator中运行时崩溃.
我只假设这是因为我的故事板上的自动布局.
有谁知道如何修理它?
2014-09-25 04:15:19.705 PSTappsperance[48327:60b] Pad AppDelegate ########
2014-09-25 04:15:27.869 PSTappsperance[48327:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil'
*** First throw call stack:
(
0 CoreFoundation 0x0000000110a5c495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001107af99e objc_exception_throw + 43
2 CoreFoundation 0x0000000110a5c2ad +[NSException raise:format:] + 205
3 Foundation 0x00000001104ec548 descriptionForLayoutAttribute_layoutItem_coefficient + 145
4 Foundation 0x00000001104ec3bc -[NSLayoutConstraint equationDescription] + 216
5 Foundation 0x00000001104ec831 -[NSLayoutConstraint description] + …
Run Code Online (Sandbox Code Playgroud) 在界面构建器中导致此警告的原因是什么?
属性不可用布局属性相对于8.0之前的iOS版本的布局边距.
我正在使用XCode 6 Beta.警告指向xml源中与属性无关的行.
我理解"与最近邻居间隔"的目的(在Xcode 6中,尤其是在Interface Builder中)但是"限制边缘"的意义是什么?
"与最近邻居间隔"是否是特定控制按钮边缘之间的链接,以及同时选中名为"约束到边距"的复选框的事实?
这个功能在Autolayout中的作用是什么?
请找一个带有复选框的屏幕截图和我正在谈论的标签,下面用红色包围:
提前感谢您对我的三个问题的答案.
我在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约束.不知道为什么!
我试图通过代码创建约束:
constraintImageCharacterTop = NSLayoutConstraint (item: image,
attribute: NSLayoutAttribute.Top,
relatedBy: NSLayoutRelation.Equal,
toItem: self.view,
attribute: NSLayoutAttribute.Top,
multiplier: 1,
constant: viewTop)
self.view.addConstraint(constraintImageCharacterTop)
Run Code Online (Sandbox Code Playgroud)
但是,我不确定NSLayoutAttribute
这种约束的权利是什么.image
应该有主要Superview的顶层空间self.view
.
这是我认为它的工作方式,但我不确定我是否正确:
我应该使用NSLayoutAttribute.Top
或NSLayoutAttribute.TopMargin
用于图像A吗?
我正在尝试创建动态调整表格视图单元格.我通过使用这个非常详细和有用的答案完成了调整大小.
但是,标签的最大宽度未正确计算heightForRowAtIndexPath
.
我的单元格当前只有一个标签contentView
,约束设置为将所有标签边缘固定到contentView
边缘.这就是我在IB中所拥有的
小区大小正与一个屏幕外细胞计算出heightForRowAtIndexPath
使用
CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
Run Code Online (Sandbox Code Playgroud)
在这个过程中,似乎它尊重约束,并且label.preferredMaxLayoutWidth
属性被设置为320,但是当标签实际被渲染时,仍然有填充.
ios ×6
autolayout ×5
objective-c ×2
swift ×2
constraints ×1
ios7 ×1
ios8 ×1
margins ×1
size-classes ×1
uilabel ×1
uitableview ×1
xcode ×1
xcode6 ×1