BenedictThe BenedictThe - 1 month ago 7x
Swift Question

A Tab bar at arbitrary position similar to Home of Instagram, in Swift

To clarify I am not looking for a tab bar on top. I am wondering if there's a solution using what already exists to create something like a TabHost/ViewPager in Android for iOS in Swift; i.e, the bar could be moved and would control a section of the screen (similar to fragments in Android). There are lots of questions offering partial solutions such as this and this mostly showing how to place tab bar on top.

Also I know containerView is supposed to be used to contain a view as part of the screen; however, managing all the communication between views is not a simple task and is error-prone. Below is a simple storyboard showing such a design.

I am wondering if there's a more efficient way to achieve a functionality similar to the tab bar in Instagram's home which is somewhat in the middle of the screen? Thanks for your input.

enter image description here


In terms of a movable tab-bar, there's nothing out of the box as per the UIKit. You could possibly find something on or similar sites which might fit the bill.

Failing that, you'd have to create a custom UIView to handle this.

In terms of handling the slit views e.g. top and bottom, it'd probably be better subclassing UIViewController and have that handle two container views as you have shown in your image.

As to communicating between viewControllers, it's not error prone in the slightest. You either use the responder chain to pass messages up the chain, create or use references between one another e.g. self.parentViewController or self.presentingViewController and in more complex ways let myViewController = self.presentingViewController!.childViewControllers[0] as? MyViewControllerClass