6

This is a weird error that may just be an issue in Xcode for all I know. I have a tab bar controller where the first view is a UITableView with (obviously) a number of cells. When you select a cell, I've set up a segue on the MainStoryboard to go to a detail view controller. I want the tab bar to be hidden when I go to the detail view, so I went into the storyboard, chose my detail view, and clicked "Hides Bottom Bar on Push" in the editor screen that starts with "Simulated Metrics."

Everything works just fine, except that when I tap on a cell, a black bar flashes at the top of the UITableView screen, dropping the tableview cells down (as if the cells are falling down below the tab bar at the bottom), just before the screen pushes over to the detail view. The effect isn't harmful at all, but it's very disconcerting, and I'd like to smooth that out.

The only fix I've found is to uncheck the "Hides Bottom Bar when Pushed" option on the storyboard. That indeed does get rid of that black bar flash, but of course the tab bar stays on the screen when I go to the detail view, which is what I don't want.

Any ideas?

Just for completeness' sake, I went ahead and ran

[self.navigationController setToolbarHidden:YES animated: YES];

on the detail view controller's viewWillAppear method (and even tried it with the storyboard option both on and off), but there was no difference. The toolbar did indeed hide just fine, but I still got that black line at the top. So weird.

user1776559
  • 61
  • 1
  • 3
  • Still working on this -- the bar that appears at the top seems to be about exactly the size of a bottom toolbar, and in fact if I recheck "shows toolbar" on my navigation controller, I get a blue toolbar at the bottom of the screen (above the tab bar) that does indeed disappear and create a black space at the top when pushed. So I think there is some disconnect there that I'm not seeing. Also, I created a new Xcode project with a tab bar and an embedded navigation/detail controller, and there were no issues. So apparently it was something I did to my code, unfortunately... – user1776559 Oct 26 '12 at 22:04
  • I continue to work on this, to no avail. Only thing that seems to fix it is to remove the bottom tab bar on my UITableViewController, which of course defeats the purpose of having a tab bar in the first place. Very strange. – user1776559 Nov 03 '12 at 17:37
  • Still no progress on this at all, unfortunately. What a mess -- I've commented out all of my custom code, and I'm still getting these cells dropping down and showing this obnoxious black bar. The toolbar also disappears when the tableview is selected, so it has something to do with my toolbar's appearance settings. But I've got another tableview in the app that works without problem, and the settings on that one are exactly the same. At this point, the only thing I can think of is to just trash the app and start over, but that would be a real pain. – user1776559 Nov 17 '12 at 23:45
  • Finally, progress! I set up the detail's viewWillAppear to automatically hide the tabbar using `self.tabBarController.tabBar.hidden = TRUE` This keeps me from having to check "Hide tab bar when pushed" in the storyboard, which means my tabBar disappears as wanted. Just in case, I flipped hidden back to FALSE in the master's viewWillAppear. But the problem now is that even though the tab bar is hidden, there's still a black, empty bar at the bottom of the screen. Guessing this is what's causing my problem, but why would I have two tab bars down there? – user1776559 Nov 18 '12 at 01:53
  • Ok, such a pain, but the problem is at least mostly solved. My understanding is that I was hiding the tab bar as needed, but the content view that I was hiding the tab bar from wasn't filling out the space that the tab bar took up. So I found some code here (http://stackoverflow.com/questions/8903569/hide-uitabbar-in-ipad-application) to grab the current content view and size it out over the former tab bar space, and that seems to work. Still don't know why I've had this issue with this tableview and no problems with others, but at least I don't have to rewrite the whole app. – user1776559 Nov 18 '12 at 02:08
  • ... And just as I write that above, I see that the app still has a problem with a black bar appearing on push, only it's now the size of the status bar, not a full tab bar. ^$(#. I'm giving up for the day. – user1776559 Nov 18 '12 at 02:27
  • Do you test on your device? I have the same issue when I test on my simulator. But on my iPad mini no problem. Device: iPad mini2 iOS version: 7.0.6 – Hugo Sep 12 '14 at 09:13

5 Answers5

2

I know it is too late !!! I ran into same issue. It seems like the Auto resizing mask for the view was incorrect to be exact the UIViewAutoresizingFlexibleTopMargin. I checked this on in the xib file. If you are trying to do it in code make sure this flag -UIViewAutoresizingFlexibleTopMargin - is not included in the autoresizing mask.

Hope this will help some one in the future

Siby
  • 318
  • 1
  • 10
  • I ran into the same issue. If I do it in the storyboard, and not in code, where do I find the UIViewAutoresizingFlexibleTopMargin setting? – Sam Mar 27 '15 at 19:56
2

I know it is a bit late, but I have same problem and I can't solve it with any of the previous answers. (I suppose this is the reason non was accepted).

The problem is that view size of the SecondViewController is same as view size of a previous ViewController, so too small to fit in a ViewController with Toolbar hidden. Thats why black background of a UITabBarController is visible at the top when transition is happening, and on a viewDidAppear view will stretch on right size.

For me it help to subclass root UITabBarController and set background color to same background color as SecondViewController has.

class RootViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = Style.backgroundColor
    }
}

Then you can leave checkbox checked inside storyboard and it will look ok.

P.S.

If you have some views, that is position on the bottom part of the view, you need to set bottom constraints so they are smaller by 49 (because this is the height of the toolbar), and then on viewDidAppear set the right constraint.

For example:
I have view that need to be position 44 px from bottom edge. Before, I have constraint set to 44 and I have some strange behaviour of that view. It was placed to height and then jump on the right place.
I fix this with setting constraint to -5 (44-49), and then in viewDidAppear set the constraint back to 44. Now I have normal behaviour of that view.

Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97
1

Wow I just had the same issue now, very painful, and no info on the net about it.

Anyway, a simple workaround for me was to change the current view's Frame moving the y coordinates up and making the height bigger by the height of the tab bar. This fixed the problem if done straight after pushing the new view onto the navigation controller. Also, there was no need to fix the Frame afterwards (it must be updated when the view is shown again).

MonoTouch code:

UIViewController viewControllerToPush = new MyViewController();
viewControllerToPush.HidesBottomBarWhenPushed = true; // I had this in the MyViewController's constructor, doesn't make any difference
this.NavigationController.PushViewController(viewControllerToPush, true);
float offset = this.TabBarController.TabBar.Frame.Height;
this.View.Frame = new System.Drawing.RectangleF(0, -offset, this.View.Frame.Width, this.View.Frame.Height + offset);

Objective C code (untested, just a translation of the monotouch code):

UIViewController *viewControllerToPush = [MyViewController new];
viewControllerToPush.hidesBottomBarWhenPushed = YES;    viewControllerToPush.hidesBottomBarWhenPushed = YES;
float offset = self.tabBarController.tabBar.frame.size.height;  float offset = self.tabBarController.tabBar.frame.size.height;
self.view.frame = CGRectMake(0, -offset, self.view.frame.width, self.view.frame.height + offset);   self.view.frame = CGRectMake(0, -offset, self.view.frame.size.width, self.view.frame.size.height + offset);
David Miani
  • 14,518
  • 2
  • 47
  • 66
0

Do this in viewWillAppear of detailViewController, it should work fine

Bhupendra
  • 2,525
  • 18
  • 20
0

subclass your navigation controller, or just find the navigation bar

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    let backdropEffectView = navigationBar.subviews[0].subviews[0].subviews[0] //_UIBackdropEffectView
    let visualEffectView: UIVisualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
    visualEffectView.frame = backdropEffectView.frame
    backdropEffectView.superview?.insertSubview(visualEffectView, aboveSubview: backdropEffectView)
    backdropEffectView.removeFromSuperview()
}
frogcjn
  • 819
  • 5
  • 21