Keyboard covers textfield in JSQMessagesViewController - ios

I am implementing the JSQMessagesViewController library for messaging. I have small issue with the keyboard, when the textfield ist edited, the keyboard covers the textfield, and i should slide it down to see what did i write.
They have a class JSQMessagesKeyboardController which is handling the keyboard..
I tried this solution from here: iPhone Keyboard Covers UITextField but nothing changed.
Does someone had the same problem, would you share possible solutions?

override
func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
keyboardController.beginListeningForKeyboard()
}

Related

Custom keyboard on UITextView shows apple keyboard first then switches to the custom keyboard

Short video of what happens when tapping on a textView:
https://www.youtube.com/watch?v=LG_r3iDJKiM
I'm trying to show my custom keyboard on a UITextView from the textViewDidBeginEditing function, The custom keyboard has been tested on UITextFields and is working as intended. Now I'm trying to get the same keyboard to work with UITextViews.
When opening the app for the first time, and tapping on a textView the first time will have this behavior, then when we tap on other textViews the custom keyboard is there directly as intended.
the Current code in my TextViewDidBeginEditing, I tried changing the order of the last 4 lines but with no success:
public func textViewDidBeginEditing(_ textView: UITextView) {
keyboard = Keyboard.sharedInstance.keyboardWithType(availableKeyboards.numbers.rawValue, returnKey:textView.returnKeyType, isSecure: false,decimalSeparator:self.decimalSeparatorCharacter, responderClass: self)
inputView.keyboardAppearance = .dark
inputView.hideAssistantBar()
inputView.inputView = keyboard
inputView.reloadInputViews()
}
This will result in the video above, I tried some other ways but no success yet:
Setting a empty UIView as the inputView, this will still result in the apple keyboard shortly appearing
let view:UIView = UIView()
textView.inputView = view
also tried doing reloadInputViews but that doesn't work either:
textView.reloadInputViews()
also tried running it all on the main tread with
DispatchQueue.main.async { }
but no success, I cannot understand why even setting a UIView() as the inputView will still shortly show the apple keyboard. Any help in the right direction would be greatly appreciated!
Thanks in advance!

While displaying an alert in IOS, keyboard does not resign from View

While displaying an alert(Wrong password) in IOS 8, keyboard opens automatically and hide the alert(just in Iphone 4s because of the screen's size), so I can't click in "OK" and I also can't dismiss keyboard because first I need to close the alert!
Keyboard hides alert
(It seems the app is recovering last keyboard's state and showing up again)
How can I close the keyboard before calling the alert?(this way the state will be "closed")
I've tried:
myTextField!.resignFirstResponder()
While calling the button, but it didn't work, the alert shows up and automatically the keyboard opens over it !
if myTextField!.resignFirstResponder() is not working properly try this when you present the alert before call this -->self.view.endEditing(true)
the above function is not work well , try
Choice -1 :Using the Responder Chain
UIApplication.sharedApplication().sendAction("resignFirstResponder", to:nil, from:nil, forEvent:nil)
This will resign the first responder (and dismiss the keyboard) every time, without you needing to send resignFirstResponder to the proper view. No matter what, this will dismiss the keyboard. It’s by far the best way to do it: no worrying about who the first responder is
Choice -2 :UIView’s endEditing
(assuming your text field is a subview of the view you call this on). Most of the time:
self.view.endEditing(true)
set Delegate to myTextField
Include
func textFieldShouldReturn(textField: UITextField) -> Bool
{
textField .resignFirstResponder()
return true
}
Other wise Try the following
var activeField : UITextField!
func textFieldDidBeginEditing(textField: UITextField)
{
activeField = textField
}
func textFieldDidEndEditing(textField: UITextField)
{
activeField = nil
}
func textFieldShouldReturn(textField: UITextField) -> Bool
{
textField .resignFirstResponder()
return true
}
Call activeField.resignFirstResponder() before alert appears
I think from iOS8 you need to use UIAlertController instead of UIAlertView. Using UiAlertView in iOS8 and above is causing keyboard to popup unnecessarily. I have seen this and i made a condition to use UIAlertController for iOS8 and above. In below version UIAlertView should work fine
This is UIAlertView bug on iOS 8.
I have same problem but UIAlertController has not problem. :3
UIAlertView was deprecated since iOS8.
https://developer.apple.com/reference/uikit/uialertview
In Swift 4 : below code worked for me
DispatchQueue.main.async() {
self.view.endEditing(true)
}

iOS - Dismiss keyboard on Return key [duplicate]

This question already has answers here:
dismiss keyboard with a uiTextView
(6 answers)
Closed 7 years ago.
I am working with a UITextView and I need to dismiss the keyboard by pressing return key.
This is what I'm doing:
class MyController: UIViewController, UITextFieldDelegate {
#IBOutlet weak var writeNote: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
self.writeNote.delegate = self
}
how to proceed? When using a UITextField I would simply call the delegate for textFieldShouldReturn method but I don't appear to find anything like that for a textView. I can not use a textField because I need a larger amount of rows. The TextView tooltip says "When a user taps a text view, a keyboard appears; when a user taps Return in the keyboard, the keyboard disappears and..." but it doesn't do it by default..
UITextView doesn't have any such direct delegate method to hide the keyboard. You have to work around with the shouldChangeTextInRange: replacementTextmethod.
In this method, you can check for a new line character and if you get one, you can resign.

UITextView doesn't switch input toolbar to custom keyboard

iOS9 Xcode7 beta6: I'm trying to switch between keyboards (custom/default) for UITextView by using reloadInputViews(). Changing UIKeyboardType and UIKeyboardAppearance by calling reloadInputViews() works perfectly. Also following code works well under iOS8.
This implies that textView is already a first responder:
private func showCustomKeyboard() {
textView.inputView = customKeyboardView
textView.reloadInputViews()
}
private func showDefaultKeyboard() {
textView.inputView = nil
textView.reloadInputViews()
}
Things like the following have made no effect and also they look like overkill:
textView.inputView.resignFirstResponder()
textView.inputView.becomeFirstResponder()
textView.inputView = customKeyboardView
textView.reloadInputViews()
I found a couple of related questions on SO but no one of them doesn't have to do with iOS9 and as I said before it does work in iOS8.
Have anyone come across this bug?
Did you try to change the order? Because you dismiss and after that show a keyboard again. Does it make sense?:
textView?.inputView.resignFirstResponder() // dismiss keyboard
textView?.inputView.becomeFirstResponder() // show keyboard
textView?.inputView = customKeyboardView // reassign new keyboard
textView?.reloadInputViews() // reload keyboard
Try:
textView?.inputView.resignFirstResponder() // dismiss keyboard
textView?.inputView = customKeyboardView // reassign new keyboard
textView?.reloadInputViews() // reload keyboard
textView?.inputView.becomeFirstResponder() // show keyboard
The bug was related to a simulator with iOS9 on the board and eventually has been fixed with unchecking Keyboard -> Connect -> Hardware Keyboard.

Cannot resign searchbar a second time

I really don't understand why this is happening. Any hints would be much appreciated.
Setup:
UIViewController with the following subviews:
UISearchBar
UITextField
UIView (with PickerView and Done button) - viewDidLoad hides it.
I have two helper functions which can be simplified as:
func showPickerView () {
myPickerSubView.alpha = 1
}
func hidePickerView () {
myPickerSubView.alpha = 0
}
(There's actually animation, sliding up and down etc. but that part works fine)
What I want is for myPickerSubView to show when the person taps on the UISearchBar or the UITextField. myPickerSubView is dismissed by the Done button on myPickerSubview.
I started with the UITextField which I got working perfectly with:
func textFieldDidBeginEditing(textField: UITextField)
{
if !(pickerSubViewVisible)
{
self.showPickerView()
}
eventFloorTextField.endEditing(true)
}
func pickerView(eventFloorPicker: UIPickerView, didSelectRow row:Int, inComponent component: Int {
//.. other processing code
self.eventFloorTextField.text = "My Pick: \(myPick)" //so the textfield gets updated
}
I wanted to use a UISearchBar instead because I wanted to uses the built in scope bar for some added functionality. So having set the UISearchBar delegate to self etc. I thought I could just do:
func searchBarTextDidBeginEditing(searchBar: UISearchBar)
{
eventFloorSearchBar.endEditing(true)
self.showPickerView()
}
When you press on the UISearchBar the first time, the PickerSubView shows up as expected. Then, no matter what I do (press on my Textfield, dismiss the PickerSubView or not,) if I tap on the UISearchBar a second time, a keyboard will come up from the bottom. If my PickerSubView is already present, the keyboard will cover it. If the PickerSubView is not present, if I tap on the UITextField, the PickerSubView will slide up behind the keyboard.
I do not know if it is significant - but the caret (blinking cursor) remains in the UISearchBar text field but even if I make it go away by tapping on the UITextfield first, when I tap UISearchBar a second time, it will always be a keyboard showing up.
I've tried resignFirstResponder as well as various other methods, but none of them seem to work.

Resources