KeyboardObserver
- 授权协议: MIT
- 开发语言: Swift
- 操作系统: iOS
- 软件首页: https://github.com/morizotter/KeyboardObserver
软件介绍
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
}
}
}
算法分析导论
(美)Robert Sedgewick、(法)Philippe Flajolet / 冯舜玺、李学武、裴伟东、等其他 / 机械工业出版社 / 2006-4 / 38.00元
本书阐述了用于算法数学分析的主要方法,所涉及的材料来自经典数学课题,包括离散数学、初等实分析、组合数学,以及来自经典的计算机科学课题,包括算法和数据结构,本书内容集中覆盖基础、重要和有趣的算法,前面侧重数学,后面集中讨论算法分析的应用,重点的算法分的的数学方法。每章包含大量习题以及参考文献,使读者可以更深入地理解书中的内容。 本书适合作为高等院校数学、计算机科学以及相关专业的本科生和研究生的......一起来看看 《算法分析导论》 这本书的介绍吧!
