KeyboardObserver 键盘事件处理开源项目

我要开发同款
匿名用户2016年01月04日
175阅读

技术信息

开源地址
https://github.com/morizotter/KeyboardObserver
授权协议
MIT

作品详情

KeyboardObserver是为了处理不太复杂的键盘事件。

特性:

处理不太复杂的键盘事件。

不是使用NSNotificatio,而是使用evet。

区别:

不用KeyboardObserver.swift

let keyboardNotificatios = [    UIKeyboardWillShowNotificatio,    UIKeyboardWillHideNotificatio,    UIKeyboardWillChageFrameNotificatio]override fuc viewDidLoad() {    super.viewDidLoad()}override fuc viewWillAppear(aimated: Bool) {    super.viewWillAppear(aimated)    keyboardNotificatios.forEach {        NSNotificatioCeter.defaultCeter().addObserver(self, selector: "keyboardEvetNotified:", ame: $0, object: il)    }}override fuc viewWillDisappear(aimated: Bool) {    super.viewWillDisappear(aimated)    keyboardNotificatios.forEach {        NSNotificatioCeter.defaultCeter().removeObserver(self, ame: $0, object: il)    }}fuc keyboardEvetNotified(otificatio: NSNotificatio) {    guard let userIfo = otificatio.userIfo else { retur }    let keyboardFrameEd = (userIfo[UIKeyboardFrameEdUserIfoKey] as! NSValue).CGRectValue()    let curve = UIViewAimatioOptios(rawValue: UIt(userIfo[UIKeyboardAimatioCurveUserIfoKey] as! NSNumber))    let duratio = NSTimeIterval(userIfo[UIKeyboardAimatioDuratioUserIfoKey] as! NSNumber)    let distace = UIScree.maiScree().bouds.height - keyboardFrameEd.origi.y    let bottom = distace >= bottomLayoutGuide.legth ? distace : bottomLayoutGuide.legth    UIView.aimateWithDuratio(duratio, delay: 0.0, optios: [curve], aimatios:        { [weak self] () -> Void i            self?.textView.cotetIset.bottom = bottom            self?.textView.scrollIdicatorIsets.bottom = bottom        } , completio: il)}

用KeyboardObserver.swift

let keyboard = KeyboardObserver()override fuc viewDidLoad() {    super.viewDidLoad()    keyboard.observe { [weak self] (evet) -> Void i        guard let s = self else { retur }        switch evet.type {        case .WillShow, .WillHide, .WillChageFrame:            let distace = UIScree.maiScree().bouds.height - evet.keyboardFrameEd.origi.y            let bottom = distace >= s.bottomLayoutGuide.legth ? distace : s.bottomLayoutGuide.legth            UIView.aimateWithDuratio(evet.duratio, delay: 0.0, optios: [evet.curve], aimatios:                { [weak self] () -> Void i                    self?.textView.cotetIset.bottom = bottom                    self?.textView.scrollIdicatorIsets.bottom = bottom                } , completio: il)        default:            break        }    }}

功能介绍

KeyboardObserver 是为了处理不太复杂的键盘事件。 特性: 处理不太复杂的键盘事件。 不是使用 NSNotification,而是使用 event。 区别: 不用 Keyboard...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论