开发者

Custom Tab Bar for iPhone changes tabs portrait to landscape orientation

开发者 https://www.devze.com 2023-02-17 01:37 出处:网络
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.

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), bu开发者_开发知识库t 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?


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


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消