2014-06-07 35 views
4

我們可以在蘋果開發人員網站中顯示的viewdidload中創建自定義鍵盤。iOS 8的自定義鍵盤高度從肖像,然後到風景,然後回到肖像

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]]; 

但是,有1個問題。當我們以縱向方式運行該程序時,自定義鍵盤的高度約爲220.然後我們切換到橫向。它不到220.奇怪的是,當我回到縱向視圖時,高度不再是220,與景觀高度相同。它永遠不會回到原來的高度。那麼,有沒有辦法改變我們將添加子視圖的視圖的高度?

回答

8

那旋轉,我在日誌中看到這些消息時,可能是與蘋果的鍵盤約束問題的一個bug,:

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. 

我已經建檔的錯誤吧。

+0

嘿woof - 你如何用鍵盤擴展記錄?我無法使用鍵盤擴展功能將日誌成功打印到控制檯 – Spentak

+0

當您在設備上運行時,更新到最新的Xcode應該可以修復日誌。有時它仍然是壞的,你可以嘗試卸載應用程序 – woof

+0

已經在最新的Xcode沒有成功。也許它只是鍵盤擴展(與其他擴展相比) – Spentak