2013-10-17 6 views
10

के साथ कीबोर्ड को मजबूर करना चाहता हूं मेरे पास ब्लूटूथ बारकोड डिवाइस है। यदि ब्लूटूथ डिवाइस को आईफोन में कनेक्ट किया गया है, तो मैं आईफोन कीबोर्ड का उपयोग करके कुछ भी नहीं लिख सकता। आप पहले से ही जानते हैं कि आईफोन कीबोर्ड चालू नहीं होता है, क्योंकि ब्लूटूथ डिवाइस कीबोर्ड को पहचाना जाता है।मैं ब्लूटूथ डिवाइस

लेकिन !!! ब्लूटूथ डिवाइस से कनेक्ट होने पर मुझे कीबोर्ड द्वारा टेक्स्टबॉक्स में कुछ लिखना होगा।

कृपया मुझे बताएं कि यह कैसे करें! :) धन्यवाद ~

+0

आप किसी भी समाधान मिला करना चाहते हैं? यहां भी यही समस्या! – kokemomuke

उत्तर

12

हम ब्लूटूथ कीबोर्ड कनेक्ट होने पर भी डिवाइस वर्चुअल कीबोर्ड दिखा सकते हैं। इसके लिए हमें inputAccessoryView का उपयोग करने की आवश्यकता है। (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptionsdelegate.m में विधि

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldBegan:) name:UITextFieldTextDidBeginEditingNotification object:nil]; 

इस विधि नीचे कॉल करेंगे जब हम ध्यान केंद्रित -

हम

@property (strong, nonatomic) UIView *inputAccessoryView; 

में सूचनाएं नीचे जोड़ने एप्लिकेशन delegate.h में नीचे दिए गए कोड को जोड़ने की आवश्यकता 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); 

} 

यह हमारे लिए ठीक काम करता है। हम ब्लूटूथ कीबोर्ड से इनपुट प्राप्त करने के लिए एक छिपे हुए टेक्स्ट फ़ील्ड का उपयोग करते हैं और अन्य सभी टेक्स्ट फ़ील्ड्स के लिए हम डिवाइस वर्चुअल कीबोर्ड का उपयोग करते हैं जो inputAccessoryView का उपयोग करके प्रदर्शित होता है।

अगर यह मदद करता है और आपको और अधिक जानकारी की आवश्यकता है तो कृपया मुझे बताएं।

+4

दुर्भाग्य से यह आईओएस 8 – fabrizotus

+3

पर काम नहीं करता है यह आईओएस 8 और 9 पर काम नहीं करता है, क्या कोई वैकल्पिक समाधान है? – Sanju

+0

किसी को भी इसका समाधान मिला? –

0

UIView सबक्लास का पालन करें UIKeyInput प्रोटोकॉल का पालन करें।

@interface SomeInputView : UIView <UIKeyInput> { 

और कार्यान्वयन फ़ाइल (मीटर)

-(BOOL)canBecomeFirstResponder { 
    return YES; 
} 

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

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

जब भी आप कीबोर्ड को दिखाने के लिए सिर्फ

संबंधित मुद्दे