Created
November 15, 2018 07:49
-
-
Save lamlv2305/6ae28c329a99f975a726bd8370a07e9e to your computer and use it in GitHub Desktop.
Update UITableView/UICollectionView content insets inside nib of UITabBarController
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
if #available(iOS 11, *) { | |
// do nothing | |
} else { | |
let tableInset: () -> UIEdgeInsets = { [weak self] in | |
let frame = self?.navigationController?.navigationBar.frame | |
let topInset = [frame?.origin.y, frame?.height].compactMap { $0 }.reduce(0, +) | |
let bottomInset = self?.tabBarController?.tabBar.frame.height ?? 0 | |
return UIEdgeInsets(top: topInset, left: 0, bottom: bottomInset, right: 0) | |
} | |
_ = tableView.rx.contentOffset | |
.asDriver() | |
.map { _ in tableInset() } | |
.drive(onNext: { [weak self] insets in | |
guard let current = self?.tableView.contentInset, current != insets else { return } | |
self?.tableView.contentInset = insets | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment