ブルートゥースキーボードが接続されている場合でも、デバイス仮想キーボードを表示できます。そのためにはinputAccessoryView
を使用する必要があります。
我々は、通知の下に追加し、アプリdelegate.hにコードの下に
@property (strong, nonatomic) UIView *inputAccessoryView;
を追加する必要が
- delegate.mで(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldBegan:) name:UITextFieldTextDidBeginEditingNotification object:nil];
我々は集中したときにこれは、メソッドの下に呼び出します。 textField
にあります。
//This function responds to all `textFieldBegan` editing
// we need to add an accessory view and use that to force the keyboards frame
// this way the keyboard appears when the bluetooth keyboard is attached.
-(void) textFieldBegan: (NSNotification *) theNotification
{
UITextField *theTextField = [theNotification object];
if (!inputAccessoryView) {
inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[inputAccessoryView setBackgroundColor:[UIColor lightGrayColor]];
}
theTextField.inputAccessoryView = inputAccessoryView;
[self performSelector:@selector(forceKeyboard) withObject:nil afterDelay:0];
}
と "forceKeyboard" のためのコードがあり、
-(void) forceKeyboard
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
inputAccessoryView.superview.frame = CGRectMake(0, 420, screenHeight, 352);
}
これが私たちのために正常に動作します。我々は、Bluetoothキーボードからの入力を得るために隠しテキストフィールドを使用し、他のすべてのテキストフィールドに対しては、inputAccessoryView
を使用して表示されるデバイス仮想キーボードを使用します。
これが役立つかどうか、さらに詳細が必要な場合は教えてください。
見つけたのですか?同じ問題がここにある! – kokemomuke