David Seek David Seek - 1 month ago 9
iOS Question

Swift / How to fix: TableView bottom cells missing in size of the UINavigationBar

I'm using this Framework to have a moving

UINavigationBar
. I have the following problem with every View (since every view has a
UITableView
or
UICollectionView
- Yes this bug appears with
UICollectionView
, too)

enter image description here

The bottom of every Screen is missing in the size of the
UINavigationBar
.

The controller is a subclass of
UIViewController
.

open class SLPagingViewSwift: UIViewController, UIScrollViewDelegate


The
UIViewControllers
are created globally:

var settingsVC: UserSettingsVC?


Instantiated within the class that creates the controller:

appDelegate.window = UIWindow(frame: UIScreen.main.bounds)

settings = settingsStb.instantiateViewController(withIdentifier: "UserSettingsVC") as? UserSettingsV
// among other VCs
self.setItems() //sets the images at the navigationbar
let items = [itemsArray]

let controllers = [arrayOfVCs] as [UIViewController]

controller = SLPagingViewSwift(items: items, controllers: controllers, showPageControl: false)
controller.indexSelected = 1

nav = UINavigationController(rootViewController: controller)
appDelegate.window?.rootViewController = nav
appDelegate.window?.backgroundColor = cachedBlack
appDelegate.window?.makeKeyAndVisible()


The example controller is a
UITableViewController
. Same bug appears in every other
UIViewController
with a
UITableView
as well as in one
UITableViewController
with a
UICollectionView
.

What am I missing? Help is very appreciated.

Answer

What you need to do is create a global constant and set the UIEdgeInsetsMake(), for example:

let collectionViewInset = UIEdgeInsetsMake(0, 0, 44, 0)

44 is the height of the navigation bar, and you need to start it after the navigationBar, so y = 44.0.

After doing that you need to set:

collectionView.contentInset = collectionViewInset

And that's it, sorted!