Iphone iOS 8自定义键盘高度从纵向更改为横向,再从横向更改为纵向

Iphone iOS 8自定义键盘高度从纵向更改为横向,再从横向更改为纵向,iphone,keyboard,autolayout,ios8,ios-app-extension,Iphone,Keyboard,Autolayout,Ios8,Ios App Extension,我们可以在viewdidload中创建自定义键盘,如apple开发者网站所示 self.nextKeyboardButton = [UIButton buttonWithType:UIButtonTypeSystem]; [self.nextKeyboardButton setTitle:NSLocalizedString(@"Next Keyboard", @"Title for 'Next Keyboard' button") forState:UIControlStateNormal];

我们可以在viewdidload中创建自定义键盘,如apple开发者网站所示

self.nextKeyboardButton = [UIButton buttonWithType:UIButtonTypeSystem];

[self.nextKeyboardButton setTitle:NSLocalizedString(@"Next Keyboard", @"Title for 'Next Keyboard' button") forState:UIControlStateNormal];
[self.nextKeyboardButton sizeToFit];
self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = NO;

[self.nextKeyboardButton addTarget:self action:@selector(advanceToNextInputMode) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:self.nextKeyboardButton];

NSLayoutConstraint *nextKeyboardButtonLeftSideConstraint = [NSLayoutConstraint constraintWithItem:self.nextKeyboardButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0];
NSLayoutConstraint *nextKeyboardButtonBottomConstraint = [NSLayoutConstraint constraintWithItem:self.nextKeyboardButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
[self.view addConstraints:@[nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint]];

然而,有一个问题。当我们以纵向方式运行该程序时,自定义键盘的高度约为220。然后我们转向风景。不到220。奇怪的是,当我回到纵向视图时,高度不再是220,而是与横向高度相同。它永远不会回到原来的高度。那么,有没有一种方法可以改变我们将添加子视图的视图高度?

这可能是苹果键盘约束问题的一个缺陷,当我在日志中看到这些消息时:

 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:0xfd04d80 V:[_UIKBCompatInputView:0xf97a580(216)]>",
        "<NSLayoutConstraint:0xe325bf0 V:[_UIKBCompatInputView:0xf97a580(162)]>"
    )

    Will attempt to recover by breaking constraint 
    <NSLayoutConstraint:0xfd04d80 V:[_UIKBCompatInputView:0xf97a580(216)]>

    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.
无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。

我已经为它提交了一个bug。

嘿,woof-你如何使用键盘分机登录?我无法使用键盘扩展成功地将日志打印到控制台更新到最新Xcode在设备上运行时应修复日志。有时它仍然损坏,您可以尝试在最新的Xcode上卸载appBeen,但没有成功。也许这只是键盘扩展(相对于其他扩展)苹果已经修复了它们的约束错误,如果你使用自动布局,并且约束有问题,这也会被打破。对我来说,它时不时地显示没有。如果没有出现此类错误,则当at VIEWD出现时,self.view中没有约束。