Reset UIKeyboard State - ios

I have a UITextView which the keyboard enters values into. However, if you clear the text value (i.e uitextview.text = #""), the keyboard's state does not reset to the lowercase alphabet keyboard.
That is, if I was in the middle of typing "hello.." and the textview gets cleared, the keyboard still shows the symbols, rather than back to the alphabetical letters.
Is there a way to get around this?

It turns out
[textview resignFirstResponder]
immediately followed by
[textview becomeFirstResponder]
does the trick. It does seem a little "hacky" though, but with Apple not providing any direct access to the keyboard, it seems that this is the only way.

Related

iOS place cursor after word in UITextView

I have a string in a UITextView.
NSString *str = #"Hello world. What #are you #doing ?"
When I tap on the UITextView the cursor goes where I tap on the string. But I need that, suppose I tap on any character of that textview, the cursor will automatically goes to the end of that word. For e.g, I tap on the character "e" in "Hello", then the cursor will place after "Hello".
How can I do this?
You have to understand the concept and underlying structure of a touch device.
Let me explain.
When you have a textfield/ textview, inside a view and your keyboard is not showing ie. textfield is inactive. The superview might have any number of gesture recognisers other than the textfield.
Hence the OS just detects the touch which will make the UI element become firstResponder, or rather Active.
After the textfield is active, OS recognises that the other gesture pattern will come into play in this moment. And in this moment you can tap in any position (or Long tap) and then place ur cursor at any character you want.
Hope you could understand.
this should be the default behavior of textview. You not need to do any additional setup for that! If you will long press then only your cursor go at particular character otherwise it will go to end of the word. this is the default behavior.

UITextView responding unexpected to accessibility voice over

Currently I am walking through my whole iOS app to optimize it for accessibility voice over. When it comes to the UITextView, which I subclassed, voice over is not acting like I thought it would. My UITextView subclass is only changing a path's color on the superview's layer in becomeFirstResponder and resignFirstResponder. So nothing special on my UITextView subclass that could interfere with accessibility.
As long as there is no text in the UITextView it is acting as expected. Voiceover tells me that it is a text field and that I can double tap it to edit. But as soon as there is text in the UITextView, the only thing voice over tells me, is the value of the UITextView. Voice over doesn't tell me anymore that this is an editable text field.
Am I doing something wrong? Why is it acting like that?
I do appreciate any help!
If you didn't edit any accessibility hints or labels for the text field it should act accordingly. If selected it should say:
It is a text field
If you are editing it
The editing mode you are in
The value of the text field (nil if empty)
Where the cursor is
Then while you type it says the letters you are entering as you enter them. When you hit space or enter it should say the word you just typed. As long as your text field is exhibiting these behaviors you should be fine.
Tip: if you want to know how accessibility elements should act, try using a native iOS app with accessibility turned on and compare it with your app.

Is there a way to set the iPhone keyboard to all caps without going through delegate

I have a textfield that can switch between a numpad and an alphanumeric keyboard (for design reasons). Here's the code:
self.tfID.keyboardType = UIKeyboardTypeAlphabet;
[self.tfID reloadInputViews];
The problem is that when I switch from numpad to alphanumeric, it doesn't automatically turn on the caps even though that field is set to UITextAutocapitalizationTypeAllCharacters. I don't want to do this through the delegate because I want to still allow the user to enter in lowercase characters if they choose so. Is there a way to do this?
Edit: After the first character is typed, the caps lock is turned back on so only the first character is lowercased.
I have tried this and it works. Instead of calling reloadInputViews on your textfield, if you call resignFirstResponder immediately followed by a becomeFirstResponder on your textfield it will auto switch to all caps again for the first character. This does slightly show the animation from lower case keys to all caps keys, but it does achieve your functional goal of getting back to all caps automatically for that first character.
self.tfID.keyboardType = UIKeyboardTypeAlphabet;
[self.tfID resignFirstResponder];
[self.tfID becomeFirstResponder];

Keyboard with only number and letters input for username field?

I have a textfield and I would like to remove the punctuation marks from the keyboard and also the spacebar. Can this be done?
AFAIK, you cannot remove anything from the keyboard without providing your own custom keyboard. You may however, intercept characters before they appear in the textfield using it's delegate method -(BOOL)textField: shouldChangeCharactersInRange: replacementString:. (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextFieldDelegate_Protocol/index.html#//apple_ref/occ/intfm/UITextFieldDelegate/textField:shouldChangeCharactersInRange:replacementString:)

Setting UITextView's editable to NO always resigns FirstResponder. Can be avoided?

My app basically lets you send a piece of text. When the user taps send, I would like to disable the text view which contains the text so the user can't edit it anymore as the text is being sent. It seems though that setting either enableUserInteraction or editable to NO always resigns the first responder (basically the keyboard is dismissed) which is a behavior I don't want. I want to keep the keyboard displayed. Is there anyway around this? Thanks in advance.
While I don't really understand why you think it's a good idea to keep the keyboard on screen if there's nothing to edit, you can achieve this by having a hidden UITextField and making that first responder.
If the UITextView's delegate method textView:shouldChangeTextInRange:replacementText: returns NO, its contents will not be changed.

Resources