代码之家  ›  专栏  ›  技术社区  ›  Mc.Lover

检测iPad键盘隐藏按钮

  •  7
  • Mc.Lover  · 技术社区  · 14 年前

    嗨,有什么方法可以检测到iPad键盘隐藏按钮吗?我是说当用户按下这个按钮时:

    会发生什么事的!

    alt text

    会发生什么事的!

    4 回复  |  直到 14 年前
        1
  •  17
  •   DarkDust    14 年前

    我不确定你想完成什么,但也许这可以帮助你:注册 NSNotificationCenter 要接收uikeyboardwillhidenotification和/或uikeyboarddidhidenotification。

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(myKeyboardWillHideHandler:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
    
    ...
    
    - (void) myKeyboardWillHideHandler:(NSNotification *)notification {
        NSLog(@"Keyboard wants to hide. What a coward.");
    }
    
        2
  •  0
  •   Vaibhav Saran    12 年前

    把这个给 viewDidLoad

    // register to track event when user presses hide keyboard button on bottom right cornor for iPAD
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldShouldReturn:) name:UIKeyboardWillHideNotification object:nil];
    

    这将使你 - (BOOL)textFieldShouldReturn:(UITextField *)textField; 在iPad中按下键盘向下按钮时调用的委托方法。

        3
  •  0
  •   Waleed Mahmood    12 年前

    [[nsnotificationcenter defaultcenter]addobserver:self-selector:@selector(textfieldShouldReturn:)name:uikeyboardwillhidenotification-object:nil];

    这实际上是在移动中崩溃。

    但如果调用自定义方法,例如: [[nsnotificationcenter defaultcenter]addobserver:self selector:@selector(mycustomermethodtoresigntextfieldpresponder)name:uikeyboardwillhidenotification object:nil];

    那就行了……-)

        4
  •  0
  •   Mercurio Cromo    10 年前

    用JavaScript

    我为ipad iOS7找到了一个解决办法。我将在IOS8上进行测试,以确保它工作正常。所以基本上我在每一个focusout事件上创建一个监听器(对于我的所有文本),然后调用我的函数。

    当你打开键盘和关闭“键盘”时,它就会启动。当您选择另一个文本字段或按钮时,它不会触发,因为它的目标为空。如果与keydown结合使用,则只能在释放键盘时保存多个值并调用提交功能。

    document.addEventListener('focusout', function(e) {
            if (e.relatedTarget == null){
                alert("close keyboard without click on something else");
                callYourFunction();
               }
        });