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
}
}
}
函数式算法设计珠玑
Richard Bird / 苏统华、孙芳媛、郝文超、徐琴 / 机械工业出版社 / 2017-4-1 / 69.00
本书采用完全崭新的方式介绍算法设计。全书由30个珠玑构成,每个珠玑单独列为一章,用于解决一个特定编程问题。这些问题的出处五花八门,有的来自游戏或拼图,有的是有趣的组合任务,还有的是散落于数据压缩及字串匹配等领域的更为熟悉的算法。每个珠玑以使用函数式编程语言Haskell对问题进行描述作为开始,每个解答均是诉诸于函数式编程法则从问题表述中计算得到。本书适用于那些喜欢学习算法设计思想的函数式编程人员、......一起来看看 《函数式算法设计珠玑》 这本书的介绍吧!
