Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop the UITextField from responding to the shake gesture?

By default, if you shake the iPhone while entering text in a UITextField, a little box will appear asking if you want to undo typing. How can I prevent this from happening? I looked through the UITextField, UITextFieldDelegate, and UITextInputTraits docs and found nothing relating to shaking.

Presumably I could subclass UITextField to ignore the shake event, but I'm not exactly confident in my ability to not screw other things up. I'd love something like

textField.respondsToShake = FALSE;

What's the best way to do this?

like image 589
Jesse Beder Avatar asked Sep 07 '10 22:09

Jesse Beder


2 Answers

[UIApplication sharedApplication].applicationSupportsShakeToEdit = NO;
like image 82
Aaron Saunders Avatar answered Oct 19 '22 19:10

Aaron Saunders


You could try to subclass UITextField and override canPerformAction:withSender: in such a way that it will disallow the undo: action. But then you lose undo both by shaking and through the context menu.

like image 2
Stefan Arentz Avatar answered Oct 19 '22 18:10

Stefan Arentz