Skip to content

Instantly share code, notes, and snippets.

@lamlv2305
Created November 15, 2018 07:49
Show Gist options
  • Save lamlv2305/6ae28c329a99f975a726bd8370a07e9e to your computer and use it in GitHub Desktop.
Save lamlv2305/6ae28c329a99f975a726bd8370a07e9e to your computer and use it in GitHub Desktop.
Update UITableView/UICollectionView content insets inside nib of UITabBarController
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