UITextFieldカスタムを使用しUIPickerViewてinputViewユーザーをいくつかのオプションに制限し、ドロップダウンリストに似た機能を持っています。Bluetooth 経由で接続されたハードウェア キーボードで使用すると、ハードウェア キーボードは my をオーバーライド (および非表示) しますinputView。ただし、関連するinputAccessoryViewものは残ります。ハードウェア キーボードの「キーボード」ボタン (通常は、vanilla のデフォルトのオンスクリーン キーボードが表示されます) を押すとUITextField、すべてが期待どおりに機能します。(これは、 myinputViewが再び表示されることを意味します。) iOS の以前のバージョン (つまり、7 以下) では、inputViewが呼び出されると常に表示されていました。
をからに設定して一時的に問題を解決しましたUITextFieldが、これはハードウェア キーボードがその特定のデフォルトとして認識されていない場合にのみ機能します。コードは次のとおりです (以下のコードの約 2/3 を参照してください)。さらにテストすると、この部分的な解決策は見かけほど役に立ちません。UIKeyboardTypeUIKeyboardTypeDefaultUIKeyboardTypeTwitterUIKeyboardTypepickerTextField.keyboardType = UIKeyboardTypeTwitter;
inputViewハードウェア キーボードを使用しているときに、どのような状況でも正しく表示するにはどうすればよいですか?
関連するコード スニペット:
-(int)setUpPickerWheelAtXLoc:(int)xLoc andYLoc:(int)yLoc {
int qwidth = width - (xLoc - FORMBORDERLEFT);
// Set up inputView (pickerView) to replace the keyboard
self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(xLoc, yLoc, qwidth, height)];
self.pickerView.delegate = self;
self.pickerView.dataSource = self;
self.pickerTextField = [[UITextField alloc] initWithFrame:CGRectMake(xLoc, yLoc, qwidth, 32)];
self.pickerTextField.delegate = self;
pickerTextField.borderStyle = UITextBorderStyleRoundedRect;
pickerTextField.layer.borderWidth = 0.3f;
pickerTextField.layer.borderColor = [[UIColor blackColor] CGColor];
pickerTextField.textColor = [UIColor blackColor];
pickerTextField.font = [UIFont systemFontOfSize:XXLARGEFONTSIZE];
pickerTextField.placeholder = @"Tap to choose from list...";
// Add pickerView as inputView
pickerTextField.inputView = self.pickerView;
pickerTextField.keyboardType = UIKeyboardTypeTwitter; // Suggested temporary solution
// Setup inputAccessoryView (Done button)
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[doneButton addTarget:self action:@selector(pickerDoneButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
doneButton.titleLabel.font = [UIFont systemFontOfSize:XXLARGEFONTSIZE];
doneButton.frame = CGRectMake(0,0,100,44);
[doneButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
doneButton.contentEdgeInsets = UIEdgeInsetsMake(0,0,0,20);
doneButton.backgroundColor = [UIColor lightGrayColor];
pickerTextField.inputAccessoryView = doneButton;
return xLoc + qwidth;
}
追加情報: 他のいくつかの場所を確認した結果、少なくとも 1 つの Apple 製品でも同様の現象が発生していることを確認しました。(8.0.2 の iPhone 6 の「Create New Apple ID」アプリ/ページ。月と日の生年月日ピッカービューを参照してください。)