当 AccessoryInputView 不存在键盘时,键盘将显示调用的通知

问题描述

我有一个名为 chatBoxView 的输入附件视图,它包含一个自定义的增长文本视图和几个用于发送消息的按钮。这个 inputAccessoryView 是在我的主视图控制器中设置的。

 override var inputAccessoryView: UIView? {
     get {
        return chatBoxView
     }
  }
    
 override var canBecomeFirstResponder: Bool {
      return true
  }
    

所以每次我去这个 viewController 时,我都会在我的屏幕底部看到 chatBoxView,这是我想要的。但是,键盘尚不可见(只有 chatBoxView),但为什么我的 KeyBoardWillShow 通知不断被调用

此外,当键盘向上时,然后在我点击外部时消失,KeyboardWilldisappear 函数调用,但 KeyBoardWillShow 函数随后被调用

这里是键盘通知功能

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        NotificationCenter.default.addobserver(self,selector: #selector(keyboardWillShow),name: UIResponder.keyboardWillShowNotification,object: nil)
        NotificationCenter.default.addobserver(self,selector: #selector(keyboardWillHide),name: UIResponder.keyboardWillHideNotification,object: nil)
}
    @objc func keyboardWillShow(notification: Notification) {
        if let keyboardHeight = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.height {
            print("Notification: Keyboard will show")
            dispatchQueue.main.async {
                self.tableView.setBottomInset(to: keyboardHeight - self.chatBoxView.frame.height)
                self.tableView.scrollToRow(at: IndexPath(row: 0,section: 0),at: .bottom,animated: true)
            }

        }
    }
    @objc func keyboardWillHide(notification: Notification) {
        print("Notification: Keyboard will hide")
        tableView.setBottomInset(to: 0.0)
    }

所以基本上,当键盘没有显示而只有附件视图时,我会收到日志“通知键盘显示”。有什么想法吗?

解决方法

在模拟器中,确保显示软键盘。 单击此处或⌘ + K

enter image description here

,

问题在于您在 import pandas as pd users = [ {"name": "John","state_of_birth": "CA","money": 0},{"name": "Andrew","money": 300},{"name": "Scott","state_of_birth": "OR","money": 20},{"name": "Travis","state_of_birth": "NY",{"name": "Bill",{"name": "Mike","money": 0} ] df = pd.DataFrame.from_records(users) # we need a column to indicate if money > 0 df["money_bool"] = df["money"] > 0 # groupby gives you an iterator of Tuple[key,sub-dataframe] # dfs now holds a list of your grouped dataframes dfs = [tup[1] for tup in df.groupby(["state_of_birth","money_bool"])] # you can now drop the money_bool column if you want dfs = [df.drop("money_bool",axis=1) for df in dfs] desired_output = [df.to_dict("records") for df in dfs] 中丢弃了重要信息。仅仅看键盘的高度是不够的。您需要查看键盘的位置——查看它的整个框架信息。如果键盘顶部不会高于屏幕底部,显然您不应该做任何事情。同样,如果键盘框架不会从原来的位置改变,那么您不应该做任何事情。