5

I'm making a tab bar application and I want not only a custom bar on the bottom , but also the ability to change what the buttons are if the user is in portrait or landscape mode.

For instance, the user is holding iphone vertically = 3 tabs (a, b, c), but the user flips the phone on its side and the tab bar now populates with 2 tabs (d, e) which are aligned up/down on the left side of the screen so the user can read them.

I have looked into subclassing the UITabBarController class but feel like what I want is not possible by doing so. I want to know...

1) how can I accomplish this?

2) is making my own tab bar going to cause issues upon pushing the application to the App Store?

1
  • Did you ever figure out how to get tabs on the left side of the screen vertically during landscape mode? I'm trying to figure out how to implement that myself.
    – NickDK
    Sep 30, 2011 at 1:45

2 Answers 2

1

I think that implementing what you describe shouldn't be a problem with the app store as long as your implementation is non-confusing and doesn't "break" standard tabbar behaviour. In other words, if it looks like a standard Apple control or is similar, it should function in a very similar way and not act 'broken' to a user who is familiar with tab bars. Apple do let you have some leeway and creativity with UI controls, if you're a bit careful about not confusing or annoying the user.

As for your implementation, subclassing UITabBarController wouldn't be a very good approach, I agree. To implement your custom tabbar, take a leaf out of Apple's book and write a UIViewController subclass which implements what you describe, based on how UITabBarController works (but avoid actually using Apple's UITabBarController in any way).

Your CustomTabBarController (let's call it that for convenience) should basically take a collection of UIViewControllers, icons and description texts for both landscape and portrait mode items. You'll need to detect rotation events in your CustomTabBarController and pass them on to the actual UIViewController currently showing -- and there will be other wiring, for example passing on the viewDidAppear messages, etc.

A good soure of inspiration and hints might be looking at other people's implementation of UIViewController aggregators. For example:

http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad

2
  • +1 for subclassing a uiviewcontroller instead. The logic of selecting/deselecting "tabs" and loading view controllers accordingly is not too complicated. Start with an array of your view controllers (as UITabBarController does), match it to your tab bar indexes and go from there. There's a lovely example of custom tab bar in an app called "Gift Plan".
    – Rog
    Mar 15, 2011 at 2:55
  • @Rog Thanks Rog, didn't know about the Gift Plan app.
    – occulus
    Mar 15, 2011 at 9:37
0

Great advice! Unfortunately, I don't trust myself to implement all of this correctly..I've only been coding in objective - c for 6mo. now. What I did find and use successfully which I think others might find helpful is the following link:

http://idevrecipes.com/2010/12/17/twitter-app-tab-bar-animation/

The guys here use a custom tab bar of their own which is very nice by itself. This allows me to edit on the fly the number of buttons that are present on the bar itself, as well as the images that correspond to those buttons and the height of the tab bar itself. In addition, I used the a notification listener to the View Controller Class that contains my tab bar to tell when the user flips the iphone. On flip I set up the tab bar differently and reload it with new items/view controllers.

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];

To address the orientation differences, I simply flipped the images that appear on the tab bar 90 degrees whichever way its flipped, so I set the items on the bar up a possible of 4 different ways.

Thanks for your advice though. If I was a little braver I might try to code the custom tab bar myself!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.