OStack程序员社区-中国程序员成长平台

标题: 隐藏按钮上的 IOS 键盘 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 07:36
标题: 隐藏按钮上的 IOS 键盘

我想监控 IOS 上的键盘隐藏按钮并触发一个事件。我说的是:

ipad keyboard

我只想在用户按下实际按钮时进行监控。我不希望键盘隐藏时的事件。



Best Answer-推荐答案


用户键盘通知观察者..

对于 swift

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillAppear"), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide"), name: UIKeyboardWillHideNotification, object: nil)


func keyboardWillAppear() {
    println("Keyboard appeared")
}

func keyboardWillHide() {
    println("Keyboard hidden")
}

对于 Objective-C

[[NSNotificationCenter defaultCenter] addObserver:self 
                                     selectorselector(keyboardWillShow 
                                         name:UIKeyboardWillShowNotification 
                                       object:nil];
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self 
                                     selectorselector(keyboardWillHide 
                                         name:UIKeyboardWillHideNotification 
                                       object:nil];

关于隐藏按钮上的 IOS 键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30568238/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4