Last active
April 28, 2017 04:00
-
-
Save efremidze/28dfcf29d2b9ac2d165f60f29117192e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Typist | |
protocol KeyboardAware { | |
var keyboard: Typist { get } | |
var contentInset: UIEdgeInsets { get } | |
var scrollIndicatorInsets: UIEdgeInsets { get } | |
} | |
extension KeyboardAware where Self: UIScrollView { | |
func observeKeyboard() { | |
keyboard.on(event: .willShow) { [unowned self] options in | |
self.contentInset.bottom = options.startFrame.height | |
self.scrollIndicatorInsets = self.contentInset | |
}.on(event: .willHide) { [unowned self] options in | |
UIView.animate(withDuration: options.animationDuration) { | |
self.contentInset.bottom = 0 | |
self.scrollIndicatorInsets = self.contentInset | |
} | |
}.start() | |
} | |
} | |
class ScrollView: UIScrollView, KeyboardAware { | |
let keyboard = Typist.shared | |
override func willMove(toSuperview newSuperview: UIView?) { | |
super.willMove(toSuperview: newSuperview) | |
observeKeyboard() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment