0

I started an iOS project for iPhone where I thought might want a tab bar. I later decided that I don't want it (I want the extra screen space) and I so I tried to delete the tab bar and set my main ViewController as the initial viewController in storyboard.

This caused a weird error where the device's orientation no longer adjusts properly. For instance, switching from portrait orientation, shown in the picture:

enter image description here

becomes this in landscape:

enter image description here

If you start the app in landscape, it will look fine, but there will be a similar result when you switch to portrait. The bug manifests in the transition between screen orientations.

I've tried the following:

  • I restored the tab bar and the problem went away. This problem is caused by how I am removing the tab bar and not some other issue.
  • I searched for other articles dealing with this issue. So far, I've only seen documentation on how to install a tab bar, not how to safely remove it.
  • I attempted to connect the tab bar to the viewController with an IBOutlet and then set tabBar.isHidden = true. It's a bad hack, but it didn't work anyway. UITabBar has no such member.
  • I've tried comparing the settings between the tabBar viewController with my desired initial viewController in the Inspector, to see what may be different. Aside from the initial viewController check-box, I don't see a setting that might be causing this.

QUESTION: Is this a settings issue in storyboard (or elsewhere), or is this just a bug? My next attempt at a solution will be to delete the entire storyboard, and then recreate it and connect it back to the viewController. That's a fair amount of work I'd like to avoid if it's unnecessary.

Any help is appreciated. If I find a solution, I'll make sure to post it. Thanks!

UPDATE: I've found a workaround by going to the UI Tab Bar Controller in the Storyboard, selecting tab bar in Tab Bar Controller Scene -> Tab Bar Controller, and then checking the 'hidden' box in the inspector. This has the desired effect of getting rid of the tab bar when the app is running. It's like it's not there.

While this allows me to proceed with the app, the tab bar stuff is unnecessary code lying around in my app that I would like to get rid of.

andrewlewisdev
  • 202
  • 2
  • 11
  • That's weird. Using a tab bar or not should not affect how the app handles rotation. Do you have any orientation related code in your viewcontroller? Have you enabled/checked all device orientations in your app? Do you have any weird autolayout constraints set up? – rodskagg Mar 04 '19 at 17:55
  • All orientations are enabled. I have a lot of code that detects when an orientation change has occurred (for handling some animations). However, all of that code only detects a change. None of it locks the device in any specific orientation. I'm pretty sure that all of my layout constraints are pretty vanilla. Also, it all works correctly except when you disconnect the tabBar navigation controller from the view controller. – andrewlewisdev Mar 04 '19 at 18:20
  • Have you debugged the view hierarchy? Is that black area part of the viewcontroller, for example? And are there any constraints that look weird? – rodskagg Mar 04 '19 at 18:21
  • Did you make your view that you have shared inside a TabBarController? Or did you add in a tabBar to the viewController? – Julian Silvestri Mar 04 '19 at 18:24
  • @andlin In the view hierarchy, the black area is the UIWindow. The view Controller is not reorienting with it. Julian, I just started a project and selected multi-tabbed app – andrewlewisdev Mar 05 '19 at 21:16

1 Answers1

1

Since I originally made this post, I've found out through experimentation that the every time I added Google's GMSMapView to a viewController, programmatically or in storyboard, I was having the above orientation issues. My original problem wasn't what I thought it was

I have since tried completely rebuilding the storyboard, viewController and all, but the problem didn't go away. I also tried overloading the orientation methods for the view to no effect.

However, if you are having this orientation problem with Google Maps sdk, imbedding the view controller that contains your GMSMapView in a tab view controller, and then hiding the tab bar (unless you want a tab bar) fixes the orientation issue in my project. It's not pretty, but it works.

andrewlewisdev
  • 202
  • 2
  • 11
  • You can edit your post by clicking the `edit` button in the bottom-left corner of your question. Alternately, you can click [here](https://stackoverflow.com/posts/54988807/edit) – Benjamin Urquhart Jun 18 '19 at 16:19
  • 1
    Sorry - I knew about the editing buttons. I meant that my entire understanding of the problem shifted. I thought the information was still useful, though. I've edited my answer to remove confusion – andrewlewisdev Jun 18 '19 at 16:23