2013-10-17 10 views
10

ブルートゥースバーコードデバイスがあります。 BluetoothデバイスをiPhoneに接続すると、iPhoneキーボードを使用して何も書き込めません。 あなたはすでに、Bluetoothデバイスが認識されたキーボードであるため、iPhoneのキーボードが表示されないことを知っています。ブルートゥースデバイスでキーボードを強制したい

でも!!! iphoneがBluetoothデバイスに接続している間、テキストボックスにキーボードで何かを書き込む必要があります。

どうすればいいですか? :) ありがとう〜

+0

見つけたのですか?同じ問題がここにある! – kokemomuke

答えて

12

ブルートゥースキーボードが接続されている場合でも、デバイス仮想キーボードを表示できます。そのためには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を使用して表示されるデバイス仮想キーボードを使用します。

これが役立つかどうか、さらに詳細が必要な場合は教えてください。

+4

残念ながら、これはIOS8で動作しません – fabrizotus

+3

これはiOS8&9では動作しませんが、代替ソリューションはありますか? – Sanju

+0

誰にも解決策が見つかりましたか? –

0

UIViewサブクラスを作成するには、UIKeyInputプロトコルに従います。

@interface SomeInputView : UIView <UIKeyInput> { 

と実装ファイル(.M)

-(BOOL)canBecomeFirstResponder { 
    return YES; 
} 

-(void)insertText:(NSString *)text { 
    //Some text entered by user 
} 

-(void)deleteBackward { 
    //Delete key pressed 
} 

であなたがキーボードを表示したいときはいつでもあなたは、すべてのソリューションを

関連する問題