हम ब्लूटूथ कीबोर्ड कनेक्ट होने पर भी डिवाइस वर्चुअल कीबोर्ड दिखा सकते हैं। इसके लिए हमें inputAccessoryView
का उपयोग करने की आवश्यकता है। (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
delegate.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
का उपयोग करके प्रदर्शित होता है।
अगर यह मदद करता है और आपको और अधिक जानकारी की आवश्यकता है तो कृपया मुझे बताएं।
आप किसी भी समाधान मिला करना चाहते हैं? यहां भी यही समस्या! – kokemomuke