iOS 获取哪个 uielement 调用了 UIKeyboardWillShowNotification

标签 ios ios5 uielement

在我的 iOS 应用程序中,我有几个可以处理用户输入的 UIElement:文本字段、可编辑的 webview 等。每次我在键盘上向这些 UIElement 中写入内容时(显然)会出现。在它发生之前,我可以通过观察 UIKeyboardWillShowNotification 来捕捉这个事件。

我想知道找出哪个 UIElement 调用了这个 Action 的方法是什么。

感谢您的帮助!

最佳答案

当用户点击的 View 设置为 FirstResponder 时键盘启动,所以我认为这个问题相当于说 how do I get the current first responder何时收到 UIKeyboardWillShowNotification?

answer to that question Thomas Muller 是按照以下方式使用类扩展:

@implementation UIView (FindFirstResponder)
- (UIView *)findFirstResponder
{
    if (self.isFirstResponder) {        
        return self;     
    }

    for (UIView *subView in self.subviews) {
        UIView *firstResponder = [subView findFirstResponder];

        if (firstResponder != nil) {
            return firstResponder;
        }
    }

    return nil;
}
@end

所以我认为您可以在 UIKeyboardWillShow 的处理程序中使用它来找出导致它的原因。

关于iOS 获取哪个 uielement 调用了 UIKeyboardWillShowNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11158813/

相关文章:

iphone - iOS 6 通用应用程序中的方向问题

printing - 如何制作 UIElement 的深拷贝?

ios - 将 CKRecordID 保存到 CloudKit

ios - 调用 UIApplication 子类方法启动 scheduledTimer

objective-c - 强制 iOS 应用以横向模式启动

uitableview - iOS Storyboard中的两个UITableView如何处理

wpf - UIElement 与 FrameworkElement

ios - Xcode中如何获取UI对象

ios - SPTPlaylistSnapshot tracksForPlayback 返回 nil

ios - 仅调用前三个号码