Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide inputAccessoryView without dismissing keyboard

I am using a toolbar in the inputAccessoryView property of a textView. When the keyboard shows, it displays the toolbar as expected. When the device is rotated I want to remove the toolbar. I tried:

 myTextView.inputAccessoryView.hidden = !layoutIsPortrait;

This does hide the toolbar, but leaves the outline of the taller keyboard behind. The keyboard is apparently still sized to fit the toolbar. It looks bad and interferes with touch events of underlying responders.

 myTextView.inputAccessoryView = nil;

Works only if I resignFirstResponder, then becomeFirstResponder again. This is not acceptable. I lose the cursor placement and content of the textView, keyboard flashes out and back.

[myTextView.inputAccessoryView removefromSuperview];

Does nothing at all. I saved a reference to the toolbar in a iVar and addressed that instead,

[myIvarReference removeFromSuperview];

That works, but again the taller outline of the keyboard is faintly visible. This time it does not interfere with touches of other views. So now this is a working solution but visually unacceptable. What else can I try to show and hide the inputAccessoryView at will?

Screenshot- the faint line above the keyboard is remnant of the removed toolbar

Rotated keyboard with toolbar removed

like image 270
Dean Davids Avatar asked Sep 24 '12 20:09

Dean Davids


2 Answers

myTextView.inputAccessoryView = nil;
[myTextView reloadInputViews];

This removes the toolbar from the view and reloads the view. This way you don't need to call resignFirstResponder and becomeFirstResponder. Additionally, this will still keep your cursor placement and content.

like image 98
Eric Appel Avatar answered Nov 03 '22 15:11

Eric Appel


None of the answers above were working for me and reloadInputViews was causing weird issues. Eventually I got it to show and hide and have touches passthrough by doing:

Hide it:

[textview.inputAccessoryView setHidden:YES];
[textview.inputAccessoryView setUserInteractionEnabled:NO];

Show it:

[textview.inputAccessoryView setHidden:NO];
[textview.inputAccessoryView setUserInteractionEnabled:YES];
like image 6
sudo Avatar answered Nov 03 '22 15:11

sudo