自定义键盘:在文本更新时收到通知

时间:2016-09-02 23:56:36

标签: ios swift ios-app-extension custom-keyboard uiinputviewcontroller

当自定义键盘修改更新的文本时,UIInputViewController中是否有方法? textWillChange / textDidChange仅通知我有关光标移动的信息。

2 个答案:

答案 0 :(得分:0)

子类UIInputView。在您的子类中,设置protocol

protocol MyCustomInputViewDidChangeDelegate {
    func customInputViewDidChange(customInputView: MyCustomInputView)
}

class MyCustomInputView: UIInputView {
    var delegate: MyCustomInputViewDidChangeDelegate?
}

UIInputViewController符合MyCustomInputViewDidChangeDelegate触摸自定义键盘时,请在适当时通过调用delegate?.customInputViewDidChange(self)将其传播给代理人。

答案 1 :(得分:0)

有UITextFieldTextDidBeginEditingNotification,UITextFieldTextDidEndEditingNotification,UITextFieldTextDidChangeNotification 你可以使用

   NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.textFieldDidChanged(_:)),    name: UITextFieldTextDidEndEditingNotification, object:self.txtAlbumName)

   NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.textFieldDidChanged(_:)),    name: UITextFieldTextDidChangeNotification, object:self.txtAlbumName)
  // ------------

  func textFieldDidChanged(sender:NSNotification) -> Void {

  }

  func textFieldDidChanged (sender:NSNotification) -> Void{

  }
}