Created
May 24, 2017 04:18
-
-
Save iamjason/078dc84f7247ec70cefed3d94c194164 to your computer and use it in GitHub Desktop.
RxSwift Helpers
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 UIKit | |
import RxCocoa | |
import RxSwift | |
// KEYBOARD STUFF | |
extension UIViewController { | |
func setupViewResizerOnKeyboardShown(bag:DisposeBag) { | |
NotificationCenter.default.rx | |
.notification(Notification.Name.UIKeyboardWillShow) | |
.bind { [weak self] (notification) in | |
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue, | |
let v = self?.view, | |
let window = v.window?.frame { | |
v.frame = CGRect(x: v.frame.origin.x, | |
y: v.frame.origin.y, | |
width: v.frame.width, | |
height: window.origin.y + window.height - keyboardSize.height) | |
} | |
}.addDisposableTo(bag) | |
NotificationCenter.default.rx | |
.notification(Notification.Name.UIKeyboardWillHide) | |
.bind { [weak self] (notification) in | |
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue, | |
let v = self?.view { | |
let viewHeight = v.frame.height | |
v.frame = CGRect(x: v.frame.origin.x, | |
y: v.frame.origin.y, | |
width: v.frame.width, | |
height: viewHeight + keyboardSize.height) | |
} | |
}.addDisposableTo(bag) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment