Twittertypes的UITabBarController?
我想制作一个使用UITabBarController的应用程序,它与iPhone和iPod touch上的Twitter应用程序类似。 (用于在内容视图之间切换的未读和滑动箭头的蓝灯)。
是否有捷径可寻? 任何开源代码?
编辑:
我已经添加了一个赏金。 我正在寻找一个适用于iOS 4和iOS 5设备的解决scheme。
编辑:
我弄乱了我的原始代码,我find了一个简单的解决scheme。 我在我的animation代码中添加了以下检查,适用于iOS 5:
// iOS 5 changes the subview hierarchy // so we need to check for it here BOOL isUsingVersionFive = NO; NSString *reqSysVer = @"5.0"; NSString *currSysVer = [[UIDevice currentDevice] systemVersion]; if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending){ //On iOS 5, otherwise use old index isUsingVersionFive = YES; }
然后,而不是这个:
CGFloat tabMiddle = CGRectGetMidX([[[[self tabBar] subviews] objectAtIndex:index] frame]);
…我用这个:
CGFloat tabMiddle = CGRectGetMidX([[[[self tabBar] subviews] objectAtIndex:index + (isUsingVersionFive ? 1 : 0)] frame]);
尽pipe如此,如果我有机会find答案中的一些东西的话。
我会创build一个标准的UITabBarController的子类,并添加一些蓝色光和滑动箭头的子视图。 不应该太难以完成。
编辑:这里有一些应该在你的子类中的东西的想法。 我甚至不知道这个代码是否会编译。
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { super.delegate = self; } return self; } - (void)viewDidLoad { [super viewDidLoad]; //Create blueLight UIImage* img = [UIImage imageNamed:@"blue_light.png"] self.blueLight = [[UIImageView alloc] initWithImage:img]; self.blueLight.center = CGPointMake(320, 460); //I'm using arbitrary numbers here, position it correctly [self.view addSubview:self.blueLight]; [self.blueLight release]; //Create arrow, similar code. } - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ //Put code here that moves (animates?) the blue light and the arrow //Tell your delegate, what just happened. if([myDelegate respondsToSelector:@selector(tabBarController:didSelectViewController:)]){ [myDelegate tabBarController:self didSelectViewController:viewController] } }
这里是你如何创build箭头
http://isagoksu.com/2009/development/iphone/fancy-uitabbar-like-tweetie/
并按照拉斐尔的答案来获得蓝光。
虽然老化后,我虽然会介入一个没有人提到的GitHub项目,但他们已经很好地重新创build了Twitter风格的标签栏,下面是链接:
https://github.com/boctor/idev-recipes/tree/master/CustomTabBar
该项目位于名为“CustomTabBar”的子文件夹中,更多信息可在此处find:
http://idevrecipes.com/2011/01/04/how-does-the-twitter-iphone-app-implement-a-custom-tab-bar/
BCTabBarController是我基于我的自定义Twitter风格标签栏上,它在iOS 4和5的作品: http : //pastebin.me/f9a876a6ad785cb0b2b7ad98b1024847
每个选项卡视图控制器应该为选项卡图像实现以下方法:
- (NSString *)iconImageName { return @"homeTabIconImage.png"; }
(在应用程序委托)你将初始化标签栏控制器如下所示:
self.tabBarController = [[[JHTabBarController alloc] init] autorelease]; self.tabBarController.delegate = self; self.tabBarController.viewControllers = [NSArray arrayWithObjects: [[[UINavigationController alloc] initWithRootViewController:[[[iPhoneHomeViewController alloc] init] autorelease]] autorelease], [[[UINavigationController alloc] initWithRootViewController:[[[iPhoneAboutUsViewController alloc] init] autorelease]] autorelease], [[[UINavigationController alloc] initWithRootViewController:[[[iPhoneContactInfoViewController alloc] init] autorelease]] autorelease], [[[UINavigationController alloc] initWithRootViewController:[[[iPhoneMapUsViewController alloc] init] autorelease]] autorelease], [[[UINavigationController alloc] initWithRootViewController:[[[iPhoneCreditsViewController alloc] init] autorelease]] autorelease], nil];
或者 ,您可以使用此方法为每个选项卡视图控制器使用自定义背景图像:
- (UIImage *)tabBarController:(JHTabBarController *)tabBarController backgroundImageForTabAtIndex:(NSInteger)index { NSString *bgImagefilePath; switch (index) { case 0: bgImagefilePath = @"homeBG.png"; break; case 1: bgImagefilePath = @"aboutBG.png"; break; case 2: bgImagefilePath = @"contactBG.png"; break; case 3: bgImagefilePath = @"mapBG.png"; break; case 4: bgImagefilePath = @"creditsBG.png"; break; default: bgImagefilePath = @"homeBG.png"; break; } return [UIImage imageNamed:bgImagefilePath]; }
标签栏顶部的箭头滑动到与Twitter标签栏相同的选项卡上。
一些截图:
就在2天之前,我为POC制作了一个这样的应用程序,事实certificate它比您想象的要容易。
首先,在我的applicationdidfinishlaunching:
方法中,我添加了imageview,其中的宽度为64,指针或箭头的图像宽度为320,屏幕宽度为320,标签栏中有5个选项卡。 你也可以计算它,如果你认为你的项目将有dynamic选项卡,然后改变相应的图像的宽度像这样。
CGRect rect = tabBarpointerImageView.frame; rect.size.width = sel.window.frame.size.width / tabbarcontroller.viewControllers.count; tabBarpointerImageView.frame = rect;
您可能还希望将该图像视图的内容模式设置为uiviewcontentmodecenter
此外,我已经设置了像这样的一些计算imageview的框架
CGRect rect = CGRectZero; rect.size.width = self.window.frame.size.width / tabbarcontroller.viewControllers.count; rect.size.height = 10;// as image was of 10 pixel height. rect.origin.y = self.window.frame.size.height - 49;// as the height of tab bar is 49 tabBarpointerImageView.frame = rect;
然后在标签栏控制器的委托方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
只需使用一个animation块来像这样animation指针的运动
[uiview beginanimation:nil context:nil]; CGRect rect = tabBarpointerImageView.frame; rect.origin.x = rect.size.width * tabbarcontroller.selectedIndex; tabBarpointerImageView.frame = rect; [uiview commitanimations];
PS。 对不起,如果一些拼写不正确。