1

在我的 uiview 中,我有 Text Field 和 Send 按钮,它是一个聊天应用程序,当该视图向上滑动时,它显示警告“与守护进程的连接无效” ,以便代码滑动键盘我正在使用 bindtokeyboard() 函数在其他任何地方都可以完美运行。

func bindToKeyboard(){
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange(_:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
    }
    @objc func keyboardWillChange(_ notification: NSNotification){
        let duration = notification.userInfo![UIResponder.keyboardAnimationDurationUserInfoKey] as! Double
        let curve = notification.userInfo![UIResponder.keyboardAnimationCurveUserInfoKey] as! UInt
        let beginingFrame = (notification.userInfo![UIResponder.keyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue
        let endFrame = (notification.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
        let deltaY = endFrame.origin.y - beginingFrame.origin.y
        UIView.animate(withDuration: duration, delay: 0.0, options: UIView.AnimationOptions(rawValue: curve), animations: {
            self.frame.origin.y += deltaY
        }, completion: nil)
        
    }
}

但是当我将它绑定到 UIView 时它不起作用。它的工作直到我输入 但是当我输入 uiview 消失并且警告出现在控制台上

4

0 回答 0