Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDK safe way to hide iPad keyboard when textview is in focus

I have some iPad app where user will navigate using touch screen OR bluetooth keyboard. I have some hidden textView which is in focus (first responder) and here I detect what is entered from keyboard.

But, when I disconnect keyboard, I have a problem, virtual keyboard appears.

Can I check if bluetooth keyboard is connected or not, and to set or resign first responder in viewDidLoad or something?

or

I have notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillAppear:) name:UIKeyboardWillShowNotification object:nil];

Can I hide keyboard on some way when keyboardWillAppear is triggered? I tried [textView resignFirstResponder], but without success :|

like image 551
dormitkon Avatar asked Dec 28 '22 00:12

dormitkon


1 Answers

You could set the inputView to a transparent view:

UIView *emptyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
emptyView.backgroundColor = [UIColor clearColor];
textView.inputView = emptyView;

In theory that would set the onscreen keyboard to an empty view so it wouldn't be visible. If it doesn't accept a view with no frame then try bumping the width and height to 1. It wouldn't affect the external keyboard; it just wouldn't show up on the device.

like image 50
Josh The Geek Avatar answered Dec 31 '22 13:12

Josh The Geek