IOS Reject / Show the keyboard without rejecting the first responder

My application is used with a barcode scanner connected via Bluetooth. When the scanner is connected, you can double-click the button on the scanner to remove / show the on-screen keyboard. 90% of the time when the user wants the keyboard to be hidden, as they will scan the barcode for data entry. There are a few exceptions that I know in advance that the keyboard must be turned on, I would like to save them when I press the scanner button to bring up the keyboard and instead make the keyboard appear.

The scanner does not use resignfirstresponder to reject the keyboard, this is due to the fact that the cursor is still displayed and barcode scanning will enter data into the current text field.

Does anyone know how to fire / show the on-screen keyboard without using resignfirstresponder?

For reference, I use this scanner http://ww1.socketmobile.com/products/bluetooth-scanners/how-to-buy/details.aspx?sku=CX2864-1336

+6
source share
3 answers

To completely complete editing in the view, you can use the following

[self.view endEditing:YES]; 

This will remove the keyboard for you in the view.

+2
source

I ran into this today and found a solution. The trick is to use a secondary text field that is off-screen or hidden with a customizable empty set of inputView and make this field the first responder. This field captures text from a hardware scanner, and the software keyboard is hidden.

However, I got this job using a very similar approach and instead made the view controller itself the first responder as an input scan view.

Example:

 class SearchViewController: UIViewController, UIKeyInput { let searchField = UITextField() let softwareKeyboardHider = UIView() override func viewDidLoad() { super.viewDidLoad() view.addSubview(searchField) inputAssistantItem.leadingBarButtonGroups = [] inputAssistantItem.trailingBarButtonGroups = [] } override var canBecomeFirstResponder: Bool { return true } override var inputView: UIView? { return softwareKeyboardHider } var hasText: Bool { return searchField.hasText } func insertText(_ text: String) { searchField.insertText(text) } func deleteBackward() { searchField.deleteBackward() } } 

Now that you want to hide the soft keyboard, make SearchViewController first responder.

To show the soft keyboard, make SearchViewController.searchField first responder.

+1
source

For those still struggling with this, you can achieve this in Swift by making the inputView of the text UIView() equal to UIView()

I.e:

 yourtextfield.inputview = UIView() 
0
source

Source: https://habr.com/ru/post/954431/


All Articles