How to detect an iOS keyboard when it is between controllers?

Just to get started: I'm already listening to the keyboard appear / disappear / change notifications. They do not shoot. Neither one is displayed / disappears / changes.

When I have the keyboard up, and click on the controller on top, which also has the keyboard up (- [UITextView getFirstResponder] in viewWillAppear), no keyboard notifications start. This makes sense, as the keyboard does not actually move in this animation, but in this case it is not desirable.

How can I determine this scenario and / or how to get the current position of the keyboard when the notification was not missed? A global, general listener is an option, but I would prefer to avoid this if possible.

+2
ios keyboard
Aug 03 2018-12-18T00:
source share
1 answer

You will need to find firstResponder, and if it is a UITextField or UITextView, then the keyboard will move up or move. No notification does not mean that it is already installed, so its old frame (relative to the window) remains valid. Unfortunately, there is no easy way to find firstReponder. I grabbed some code that recursively went through all the current views in the view, looking for it.

EDIT:

- (UIView *)findFirstResponder { if (self.isFirstResponder) { return self; } for (UIView *subView in self.subviews) { UIView *firstResponder = [subView findFirstResponder]; if (firstResponder) return firstResponder; } return nil; } 
0
Aug 03 '12 at 18:21
source share



All Articles