繁体   English   中英

在iOS8自定义键盘中无法获得约束

[英]Can't get constraints right in iOS8 custom keyboard

我在iOS 8中遇到了自动布局的主要问题。我正在使用自定义键盘,但我无法让视图以正确的高度显示。 设备上呈现的视图太低,更像是单独的UIImageView的预期高度。 我已经设置了约束,如图所示:

XCode截图

但是我一直在日志中得到这个错误,它没有告诉我任何事情(可能是因为我不明白在哪里看):

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自定义键盘中的代码:更改高度 ,但它仍然无法正常工作。

编辑:

我正在使用以下函数设置高度约束:

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!)
    }
}

这看起来像iOS自定义键盘实现中的错误。 目前的解决方法是将约束的优先级调整为大于/小于1000

该错误告诉您有冲突的约束。 UIView-Encapsulated-Layout-Height似乎是一个预定义的高度(搜索时我大多发现它在UICollectionView用法参考)。 我的猜测是,它是操作系统定义的高度,允许你的键盘。 另一个约束很可能是您创建的视图的内在内容大小(316和30确实加起来为246)。

我的结论是,当你改变高度时,你可能做错了什么。 由于我对键盘扩展开发不太熟悉,我无法告诉你什么。 然而,当涉及到我已经使用过的今日扩展时,有一种方法可以覆盖指定小部件的高度。

这类似于如何提供TodayExtension高度。 尝试这个:

self.preferredContentSize = CGSizeMake(320, 246);

这就是我如何设置今天扩展的高度与明确设置高度约束的高度。 我会自己尝试一下,现在就把一个示例键盘项目放在一起。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM