我想监控 IOS 上的键盘隐藏按钮并触发一个事件。我说的是:
我只想在用户按下实际按钮时进行监控。我不希望键盘隐藏时的事件。
Best Answer-推荐答案 strong>
用户键盘通知观察者..
对于 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/
|