Search code examples
iosswiftfixed

View fixed at the bottom Swift


I'm sorry if someone had asked that question before, I didn't find the same. I have a view with an image and it has to be always fixed a the bottom in my iOS Swift app. Even if I go to another screen it still has to be at the bottom, and it has to be the same view, not different ones for different screens. Thank you


Solution

  • Make the root view controller for your app a generic UIViewController.

    Add your image view to the bottom of your root view controller

    Drag a container view onto that view controller. Make the container view extend down to just above your image view.

    Now create a new view controller scene in your storyboard. It can be a navigation view controller if you want a navigation stack, or a tab bar controller, or whatever type you want.

    Control-drag from the container view on your root view controller onto your new view controller. Select "embed" in the dialog that appears. You have now created an embed segue, and your root view controller contains a child view controller.

    Now, do all your navigation from your child view controller. It will always occupy most, but not all of the screen, and the root view controller will still be visible with the image view at its bottom.