RXSwift 键盘监听 好用

        //监听键盘弹出通知
        _ = NotificationCenter.default.rx
            .notification(UIResponder.keyboardWillShowNotification)
            .take(until: self.rx.deallocated) //页面销毁自动移除通知监听
            .subscribe(onNext: { _ in
                print("键盘出现了")

            })
         
        //监听键盘隐藏通知
        _ = NotificationCenter.default.rx
            .notification(UIResponder.keyboardWillHideNotification)
            .take(until: self.rx.deallocated) //页面销毁自动移除通知监听
            .subscribe(onNext: { _ in
                print("键盘消失了")

            })

你可能感兴趣的:(RXSwift 键盘监听 好用)