I want to always display keyboard in all views in pageviewcontroller.
All views have uitextfield and I coded becomefirstresponder in viewdidload so the keyboard appears.
But problem is that when i set new viewcontroller or swipe in pageviewcontroller the keyboard disappears and re-appears.
Can I always show keyboard?
Thanks.
Go simple.. set invisible textfield (means hidden one)! Set that as a first responder basically, this text field should be in base view controller means out of page view. as soon as you swipe the page shift responder to the required text field. hence it will not disappear and appear on page shift.
UITextField resigns as first responder on any tap/swipe gesture. You need to handle it in your scrollview delegate method when you detect the scroll ended and then set the current page view controller's UITextField as first responder.
Related
As you can see in the below gif there is a flash as the keyboard momentarily dismisses as the input in the home screen loses focus and reopens as the text field in the second screen gains focus. Is there a way to keep the keyboard open while as the modal is presented?
My not be the right answer but when you are dismissing the view, how are you going about this?
If you are dismissing the first responder, I'm imaging that the first responder is in fact the keyboard on the first view. Are you dismissing the keyboard and then dismissing the view or is it doing that automatically when you are dismissing the view and the keyboard belongs to the first view? Could you try and add some kind of tag to the textField's and then before dismissing the view and moving to the second view, assign the first responder to be the textField in the second view?
Sorry, can't comment yet due to reputation.
I want to add a cancel button to hide the keyboard if the user wants to. I cant find any solution for swift 3.
Take a look at the documentation of a UITextField's inputAccessoryView: https://developer.apple.com/reference/uikit/uitextfield/1619627-inputaccessoryview
Assigning a view to this property causes that view to be displayed above the standard system keyboard (or above the custom input view if one is provided) when the text field becomes the first responder. For example, you could use this property to attach a custom toolbar to the keyboard.
I recommend to assign a UIToolbar that contains your cancel button to the inputAccessoryView of the UITextField that needs the cancel button. Then hook up an action to the button that resigns the first responder from the UITextField.
I have a question in regards to the color of the keyboard after a modal is dismissed. Basically, the flow goes like this...
I press a toolbar button on a keyboard that brings up a modal view controller.
That modal view controller dismisses itself and then calls a method on the presenting view controller that makes a text field first responder.
Here are some photos
Weirdly colored keyboard
Normal keyboard
In case it helps, I can get from the weirdly colored keyboard to the normal keyboard by pressing the shift key.
I saw this happen when I inadvertently tried to make my input field first responder twice and also when I let the system resign and re-establish first responder around my modal
I fixed the problem by manually resigning first responder before my modal was presented, and then manually becoming first responder again after my modal was dismissed.
You might just try manually resigning first responder before you present your modal.
In my app, I have a textfield that takes its input from a picker view. However, the user could not find his preferred option so I added above the textfield a small button resembling a keyboard. Once the button is pressed the textfield's picker view should disappear and the keyboard should appear instead so that the user enter his preferred data. So how can I do that? I tried resigning it as first responder and then making it become the first responder hoping the picker could be released as the input view but it didn't work. Adding a textfield as an accessory input view will not look right (having two textfield the user should update the first one instead).
How do you display the virtual keyboard in ios6 Simulator (iphone or iPad) ? I've tried the toggle keyboard option, but nothing appears, can you only make it appear with code? and if so, how?
Thanks for any advice.
You can't show the keyboard without a 'target'. The system needs to know where it should send the entered text to.
So if you have a subclass of UIView that accepts text input (UITextField for example), the keyboard is either shown when the user taps that view or you can programmatically trigger it by calling:
[textField becomeFirstResponder];
From iOS-Documentation Managing the Keyboard:
Displaying the Keyboard
When the user taps a view, the system automatically designates that view as the first responder. When this happens to a view that contains editable text, the view initiates an editing session for that text. At the beginning of that editing session, the view asks the system to display the keyboard, if it is not already visible. If the keyboard is already visible, the change in first responder causes text input from the keyboard to be redirected to the newly tapped view.
Because the keyboard is displayed automatically when a view becomes the first responder, you often do not need to do anything to display it. However, you can programmatically display the keyboard for an editable text view by calling that view’s becomeFirstResponder method. Calling this method makes the target view the first responder and begins the editing process just as if the user had tapped on the view.
If your application manages several text-based views on a single screen, it is a good idea to track which view is currently the first responder so that you can dismiss the keyboard later.