1

Im having a problem here. Basically within my app I have 4 elements (these 3 bottoms view "buttons" and a top bar-like view) that need to stay in front of EVERYTHING (as in the uppermost index) at ALL TIMES.

I have a series of segues set up that move horizontally to the left or right, and I want the content on these view controller to move left or right with the segue but I need these 3 views to stay static, i.e. not moving, on top.

To accomplish this I created an "overlordviewcontroller" where I add the first view controller programmatically and then make my buttons at the bottom call the segue from that child viewcontrolleR:

controller = storyboard!.instantiateViewControllerWithIdentifier("mainView")
        container.addSubview(controller.view)
        addChildViewController(controller)
        controller.view.frame = self.view.frame
        view.addSubview(controller.view)
        view.bringSubviewToFront(topBar)
        view.bringSubviewToFront(btn1)
        view.bringSubviewToFront(btn2)
        view.bringSubviewToFront(btn3)

and

controller.performSegueWithIdentifier("toMessageView", sender: controller)

The initial instantiation works great, meaning I have those 4 views on top. Problem is after I call the segue, even if I put this all right after it:

view.bringSubviewToFront(topBar)
            view.bringSubviewToFront(btn1)
            view.bringSubviewToFront(btn2)
            view.bringSubviewToFront(btn3)

These views don't stay static. The 2nd view controller clearly moves in from the right ON TOP OF these elements, ruining the effect. Then once I go back from that view controller to the original, the original is on top and we go all over again.

I have tried using container views like so:

enter image description here

Then putting the first controller as a subview of the container:

container.addSubview(controller.view)

But this had no effect. How can I do this? What do I need to do here?

blue
  • 7,175
  • 16
  • 81
  • 179

1 Answers1

-1

Are you not using a tab bar controller or a navigation controller? If not I would suggest using them. You can embed a tab bar controller into a nav bar controller or vice versa, and then have the three view controllers for your three different tabs. Then it would just be a matter of getting the sliding animation between them.

Below are links to apple's website for Nav Bar and Tab Bar documentation:

https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html

https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/TabBarControllers.html#//apple_ref/doc/uid/TP40011313-CH3-SW1

Here is an example of how to do just that:

Swift-How do I add Tab Bar AND Navigation Bar to a single view controller?

Community
  • 1
  • 1
Jonah Starling
  • 539
  • 6
  • 20
  • I really don't want to- they did not have the right look. I need a way to keep these views always above the sub view controller. – blue Aug 15 '16 at 22:47
  • @skyguy you could always try presenting the segue in the over context or over full screen mode. Not sure if that is what you are looking for though – Jonah Starling Aug 15 '16 at 22:51
  • can you provide an example? – blue Aug 15 '16 at 22:52
  • And @JonahStarling if I use navigation controller how can I keep the top bar always on top? – blue Aug 15 '16 at 22:55
  • @skyguy click on the segue, click on the attributes inspector, then try changing your presentation mode to over full screen or over current context. – Jonah Starling Aug 15 '16 at 22:55
  • @skyguy if you use a navigation controller the top bar will always be on top as long as the view controller is a child of it – Jonah Starling Aug 15 '16 at 22:56
  • That didn't work. I changed the context on the vcs since the segue didn't have any, but no difference. – blue Aug 15 '16 at 22:58
  • why doesn't the container view work then? If the 4 views are on top of that container? – blue Aug 15 '16 at 22:58
  • I would suggest looking here for more on containers. Sorry I couldn't be of more help. https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html – Jonah Starling Aug 15 '16 at 23:15
  • 1
    I'm agreement with Jonah, as you are recreating functionality that is built into UINavigationController and UITabbarController. If your objection is based on the appearance of the navigation and tab bar, you can use their appearance proxy to customize how they appear on screen. See these two articles on AppCoda : https://www.appcoda.com/tag/uiappearance/ – Scott Ahten Aug 15 '16 at 23:56
  • 1
    If you can't get the appearance you're looking by customizing UINavigationControler, you can always subclass it, hide it's navigation bar and add your own subviews. From there, you can push and pop view controllers using segues in interface builder. – Scott Ahten Aug 16 '16 at 00:00
  • 1
    If you do not like the way the tab bar cuts from one view controller to the next, see this Stack Overflow answer on how to animate transitions between controllers: http://stackoverflow.com/questions/5161730/iphone-how-to-switch-tabs-with-an-animation – Scott Ahten Aug 16 '16 at 00:05