1

How can I block keyboard for input (something like userInteractionEnabled = NO) in iOS >= 4 ?

Keyboard is used for TextEdit.

If I disable interaction for textedit then keyboard disappears, but I want to see the keyboard.

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
Le_Coeur
  • 1,521
  • 5
  • 28
  • 44
  • Which UI control? Most if not all controls still have an userInteractionEnabled property as far as I know? – JiaYow Feb 24 '12 at 11:22
  • the answer is in your question itself! userInteractionEnabled = NO; – Selvin Feb 24 '12 at 11:23
  • userInteractionEnabled = NO; -> Does not work, keyboard disappears! – Le_Coeur Feb 24 '12 at 11:30
  • Not sure why you would want to block input (I'm sure it's a completely logical reason), but if you have a visible keyboard and users can't type with it, Apple may reject your app because it could be confusing to users. – TigerCoding Feb 24 '12 at 11:34
  • You could hookup the ValueChanged method in the TextEdit delegate and just set it to clear the text box. – JDx Feb 24 '12 at 11:36
  • I need it for password lock for my App (Apple do same thing with iphone pass lock) – Le_Coeur Feb 24 '12 at 11:39
  • Are you looking something like user can see the keyboard but typing is disabled? – iphonedev23 Feb 24 '12 at 11:39

3 Answers3

4

have you tried this delegate?

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
iphonedev23
  • 991
  • 2
  • 12
  • 24
  • Like he said. Use that function and simply return no. The keyboard might be still active, but all the input will be blocked – BBog Feb 24 '12 at 13:04
1

Le Coeur, I think you need to consider a different approach to whatever you're trying to achieve by restricting the keyboard input for two good reasons:

  1. A UIElement that engages the user to type but doesn't react to any of the user's gestures is sure to be rejected by Apple.

  2. Because this keyboard is on the OS level, it is private API and I am pretty sure there is nothing you can do to the keyboard to block access to the keys.

Hope this helps

Stavash
  • 14,244
  • 5
  • 52
  • 80
  • Hm, how about Apple's Pass Lock? They block keyboard also! – Le_Coeur Feb 24 '12 at 11:40
  • By doing what? Do you simply see a keyboard with no blocking/obstructing view on top and it is not reacting? Does it look different when it's disabled? – Stavash Feb 24 '12 at 11:42
  • Same principle as by Apple pass lock, after 5 attempts block for some interval... – Le_Coeur Feb 24 '12 at 11:48
  • The best user experience, I think, would be to show a semi-opaque view that suggests that the keyboard is not available. Try creating a UIView with alpha=0.5 and backgroundColor=[UIColor blackColor]. Set it's userInteractionEnabled to NO and add it as a subview to your [UIApplication sharedApplication].keyWindow - This way you don't need to mess with the keyboard properties and you also show the user he has no access to the input. – Stavash Feb 24 '12 at 11:58
  • But the keyboard is always over my subview :( – Le_Coeur Feb 24 '12 at 12:16
  • Even if you add it to the keyWindow? Hmm... can't think of a different way other than simply erasing anything typed in immediately by using the delegate method "shouldChangeCharactersInRange"... Sorry – Stavash Feb 24 '12 at 12:22
0

You can always disable userInteractionEnabled on the keyboard view, or less-dangerously add an invisible subview to the keyboard that blocks interaction. See iOS: How to access the `UIKeyboard`? on how to get the UIView for the keyboard.

Community
  • 1
  • 1
Mike Katz
  • 2,060
  • 2
  • 17
  • 25