Skip to content

Make IQ work when keyboard is already shown #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Make IQ work when keyboard is already shown #5

wants to merge 1 commit into from

Conversation

mrvincenzo
Copy link

Make IQKeyboard work when the keyboard is already shown and the UITextField/UITextView becomes first responder (in this case UIKeyboardWillShowNotification is not fired). Also IQ before this change didn't work for me for UITextView (worked only for UITextField). After the change IQ is working well both for UITextField and UITextView.

Make IQKeyboard work when the keyboard is already shown and the
UITextField/UITextView becomes first responder (in this case
UIKeyboardWillShowNotification is not fired). Also IQ before this
change didn't work for me for UITextView (worked only for UITextField).
After the change IQ is working well both for UITextField and UITextView.
@hackiftekhar
Copy link
Owner

Hi mrvincenzo,
Firstly I thanks for your support.

First I clarify that UIKeyboardWillShowNotification is also fired when Any UITextField/UITextView becomes first responder. For more information see 'IQKeyBoardManager.m'. I have added a NSNotification control flow chart for you.

Second thing I forgot to write this code on 'textViewDidBeginEditing'. I only added this code on textFieldDidBeginEditing. This was my mistake.

if (isKeyboardShowing == NO)
{
    UIViewController *rootController = [IQKeyBoardManager topMostController];
    topViewBeginRect = rootController.view.frame;
}

I Think this issue has been fixed now. Please review code once again, and comment back, if I didn't understand exact issue or issue has not been fixed. I have pushed my updated code.

Thanks
Iftekhar

@mrvincenzo
Copy link
Author

Hi Iftekhar,

I thought that you probably missed the code you mentioned for textViewDidBeginEditing that's why I moved it to a separate method that is called both for UITextField and UITextView. As for the UIKeyboardWillShowNotification - I had two issues with it. First is that for me, in case of UITextView, the notification was fired before the delegate call to textViewDidBeginEditing. Therefore, the UITextView frame wasn't adjusted at all. I tested it on iOS 6. Second is that when the keyboard is already shown for UITextField/View X, and UITextField/View Y became the responder, the keyboard remains and the UIKeyboardWillShowNotification is not fired. Like with the first issue, the frame of Y is not adjusted at all.

Another issue that I saw but didn't have a chance to look in is that when you constantly switched between 2 UITextField/UITextView the frame was not restored correctly. In my case one was UITextField (say X) and the other was UITextView (say Y). I tapped on the X, on Y, on X, on Y and so on. Zeroing the keyboardDistanceFromTextField variable fixed the issue for me but it is a patch and not a real fix.

Regards,
Ilia

@hackiftekhar
Copy link
Owner

Hi mrvincenzo,
Thanks for explaining this issue in detail. I will look this issue very deeply whenever i have some time to fix it in a standard way not by just a patch. Anyway you fixed that for you.

Again very very thanks for your bug report and help me to improve IQKeyboardManager.

Regards
Iftekhar

@heefan
Copy link

heefan commented Oct 6, 2013

Hi Iftekhar,

I also found this issue that UITextView doesn't work although you have added -textFieldDidBeginEditing. Actually for UITextField, the notification sequence is the following,
UITextFieldTextDidBeginEditingNotification -> UIKeyboardWillShowNotification,

however, for UITextView, the notification sequence is the following,
UIKeyboardWillShowNotification -> UITextViewTextDidBeginEditingNotification

This is why your UITextField works well, but UITextField not. The easiest way to solve it, I change ``UIKeyboardWillShowNotificationasUIKeyboardDidShowNotification`. And the sequence become,
`UITextFieldTextDidBeginEditingNotification` or `UITextViewTextDidBeginEditingNotification` -> `UIKeyboardWillShowNotification`. It works well for me.
Well, this may change your design purpose. You may want to move view first and then display keyboard.
My changes will display keyboard first and then move view.

Hope this helpful.

Thanks & Regards
Heefan

@heefan
Copy link

heefan commented Oct 6, 2013

plus: I also agree @mrvincenzo . For UITextField case, your class member UIView *textFieldView; is nil when called -keyboardWillShow. So it will not change view position.

@hackiftekhar
Copy link
Owner

OK, now i understand the issue behind this. @heefan i merged your pull request. I think it should work fine now. @mrvincenzo Again thanks for the bug report.

@mrvincenzo
Copy link
Author

Good job nailing it. Still there is a bug I described in detail in my previous comments. My original pull request had a fix for this issue.

When a keyboard already shown for some UITextView/UITextField and you select another UITextView/UITextField, the UIKeyboardWillShowNotification is not fired and no adjustments are made!

@heefan
Copy link

heefan commented Oct 9, 2013

Hi @mrvincenzo ,

The latest code does not have UIKeyboardWillShowNotification notification any more. Is the bug still there?

@mrvincenzo
Copy link
Author

The bug is still there. My bad, I meant UIKeyboardDidShowNotification.

@hackiftekhar
Copy link
Owner

We need to manage it somehow. Without that i think it is not possible to maintain it automatically.

@mrvincenzo
Copy link
Author

Exactly. Thats what I am doing in my fork. You can compare your IQKeyboardManager.m and the one from my fork.

In your demo, the keyboardDidShow is fired every time because of

 [textField addPreviousNextDoneOnKeyboardWithTarget:self previousAction:@selector(previousClicked:) nextAction:@selector(nextClicked:) doneAction:@selector(doneClicked:)];

in viewDidLoad in the ViewController.m. Comment it out and see what happens.

I suggest the following logic - when the didBeginEditing notification is fired then either:

  1. The keyboard is not yet shown (isKeyboardShowing == NO) - your code already handles it
  2. The keyboard is already shown (isKeyboardShowing == YES) - call the code in keyboardDidShow that adjust the frame.

It is already working in my fork. I can send a pull request if you want.

@hackiftekhar
Copy link
Owner

ok, please send me pull request of your repository.

@heefan
Copy link

heefan commented Oct 11, 2013

Hi @mrvincenzo, I probably miss some cases. Thanks for pointing out this issue.

@hackiftekhar
Copy link
Owner

I noticed that, when UIKeyboard doesn't have any inputAccessoryView then keyboardWillShow and keyboardDidShow doesn't called. This may be a case for IQKeyboardManager.

@hackiftekhar
Copy link
Owner

I also updated iOS NSNotification Machanism for textView. I Observed that, when beginning textField, or switching between textFields, the notification mechanism is almost same. But when we begin textView Editing or switching between them the notification mechanism is very different from textField even if between textView (Beginning/Switching).

@hackiftekhar
Copy link
Owner

Finally fully functional with UITextView.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants