【发布时间】:2014-11-30 20:14:23
【问题描述】:
我在 iOS 8 中的自动布局方面遇到了重大问题。我正在使用自定义键盘,但我无法让视图以正确的高度显示。设备上的渲染视图太低,更像是 UIImageView 的预期高度。如图所示,我已经设置了约束:
但我在日志中不断收到此错误,这并没有告诉我任何信息(可能是因为我不知道在哪里查看):
2014-12-06 19:56:45.095 [40268:12181198] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this:(1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x600000096940 V:[UIInputView:0x7fe780d3f600(246)]>",
"<NSLayoutConstraint:0x600000097390 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x7fe780d3f600(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000096940 V:[UIInputView:0x7fe780d3f600(246)]>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
我已尝试按照iOS 8 Custom Keyboard: Changing the Height 中的代码进行操作,但仍然无法正常工作。
编辑:
我正在使用以下函数设置我的高度限制:
override func updateViewConstraints() {
super.updateViewConstraints()
// Add custom view sizing constraints here
let changeToOrientation = deviceInfoService.getOrientationForView(self.inputView)
if (changeToOrientation == Orientation.Portrait) {
self._heightConstraint!.constant = 246
self.inputView.addConstraint(self._heightConstraint!)
} else {
self._heightConstraint!.constant = 192
self.inputView.addConstraint(self._heightConstraint!)
}
}
【问题讨论】:
-
你能把剩下的日志也加进去吗?特别是前面提到的关于
translatesAutoresizingMaskIntoConstraints的部分。 -
使用 AutoLayout 时你一般不想设置
.translatesAutoresizingMaskIntoConstraints = no? -
我已经添加了日志的缺失部分。
标签: ios swift ios-app-extension