KeyboardObserver

码农软件 · 软件分类 · 键盘(Keyboard) · 2019-07-15 07:42:17

软件介绍

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

特性:

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

  • 不是使用 NSNotification,而是使用 event。

区别:

不用 KeyboardObserver.swift

let keyboardNotifications = [
    UIKeyboardWillShowNotification,
    UIKeyboardWillHideNotification,
    UIKeyboardWillChangeFrameNotification
]
override func viewDidLoad() {    super.viewDidLoad()
}
override func viewWillAppear(animated: Bool) {    super.viewWillAppear(animated)

    keyboardNotifications.forEach {
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardEventNotified:", name: $0, object: nil)
    }
}
override func viewWillDisappear(animated: Bool) {    super.viewWillDisappear(animated)

    keyboardNotifications.forEach {
        NSNotificationCenter.defaultCenter().removeObserver(self, name: $0, object: nil)
    }
}func keyboardEventNotified(notification: NSNotification) {    guard let userInfo = notification.userInfo else { return }    let keyboardFrameEnd = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()    let curve = UIViewAnimationOptions(rawValue: UInt(userInfo[UIKeyboardAnimationCurveUserInfoKey] as! NSNumber))    let duration = NSTimeInterval(userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber)    let distance = UIScreen.mainScreen().bounds.height - keyboardFrameEnd.origin.y    let bottom = distance >= bottomLayoutGuide.length ? distance : bottomLayoutGuide.length

    UIView.animateWithDuration(duration, delay: 0.0, options: [curve], animations:
        { [weak self] () -> Void in
            self?.textView.contentInset.bottom = bottom            self?.textView.scrollIndicatorInsets.bottom = bottom
        } , completion: nil)
}

用 KeyboardObserver.swift

let keyboard = KeyboardObserver()override func viewDidLoad() {    super.viewDidLoad()

    keyboard.observe { [weak self] (event) -> Void in
        guard let s = self else { return }        switch event.type {        case .WillShow, .WillHide, .WillChangeFrame:            let distance = UIScreen.mainScreen().bounds.height - event.keyboardFrameEnd.origin.y            let bottom = distance >= s.bottomLayoutGuide.length ? distance : s.bottomLayoutGuide.length

            UIView.animateWithDuration(event.duration, delay: 0.0, options: [event.curve], animations:
                { [weak self] () -> Void in
                    self?.textView.contentInset.bottom = bottom                    self?.textView.scrollIndicatorInsets.bottom = bottom
                } , completion: nil)        default:            break
        }
    }
}

本文地址:https://codercto.com/soft/d/10163.html

Node.js:来一打 C++ 扩展

Node.js:来一打 C++ 扩展

死月 / 电子工业出版社 / 2018-6-1 / 109

Node.js 作为近几年新兴的一种编程运行时,托 V8 引擎的福,在作为后端服务时有比较高的运行效率,在很多场景下对于我们的日常开发足够用了。不过,它还为开发者开了一个使用C++ 开发 Node.js 原生扩展的口子,让开发者进行项目开发时有了更多的选择。 《Node.js:来一打 C++ 扩展》以 Chrome V8 的知识作为基础,配合 GYP 的一些内容,将教会大家如何使用 Node......一起来看看 《Node.js:来一打 C++ 扩展》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具