从键盘通知获取 UITextField

Get UITextField from Keyboard Notifications

我正在尝试获取 UITextField 正在调用观察者 UIKeyboardDidShowNotification 的那个。

我的 Observer 在 appdelegate 中,我有几个 UIViewController,其中有几个 UITextField,简而言之,我不知道当前的 First Responder。

如何在我的方法中获取在键盘通知时触发的第一响应者 UIKeyboardDidShowNotification

这不可能从 UIKeyboardDidShowNotification 中推断出来,因为它仅包含以下信息。但是,请查看此 SO thread,其中有一个关于如何获得当前第一响应者的绝妙解决方案。

NSConcreteNotification 0x7ff14d1ac0d0 {name = UIKeyboardWillShowNotification; userInfo = { UIKeyboardAnimationCurveUserInfoKey = 7; UIKeyboardAnimationDurationUserInfoKey = "0.25"; UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}"; UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 676}"; UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 460}"; UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 216}}"; UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 352}, {320, 216}}"; UIKeyboardIsLocalUserInfoKey = 1; }}