Created
March 2, 2018 03:30
-
-
Save mitsuse/13535034be747ea8ee4c4ad9de0a9d03 to your computer and use it in GitHub Desktop.
同じタブを二度タップして titleView を first responder にする
This file contains 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 | |
final class TabBarController: UITabBarController { | |
private let disposeBag = DisposeBag() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
rx.didSelect | |
.withPrevious() | |
.subscribe(onNext: { previous, next in | |
guard previous == next, let topViewController = (next as? UINavigationController)?.topViewController else { return } | |
topViewController.navigationItem.titleView?.becomeFirstResponder() | |
}) | |
.disposed(by: disposeBag) | |
} | |
} | |
extension ObservableType { | |
public func withPrevious() -> Observable<(E?, E?)> { | |
return self | |
.scan((nil, nil)) { state, next in let (_, previous) = state; return (previous, next) } | |
.skip(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment