Iphone Twitter风格的阿巴斯控制器?
我想制作一个应用程序,它使用一个uitabarcontroller,类似于iPhone和iPodtouch的Twitter应用程序。(蓝色指示灯表示未读,滑动箭头表示在内容视图之间切换) 有没有一个简单的方法可以做到这一点?有开源代码吗 编辑: 我加了一笔赏金。我正在寻找一个能够跨设备、在iOS 4和iOS 5上工作的答案 编辑: 我弄乱了我的原始代码,我找到了一个简单的解决方案。我在我的动画代码中为iOS 5添加了以下检查:Iphone Twitter风格的阿巴斯控制器?,iphone,twitter,uitabbarcontroller,ios,Iphone,Twitter,Uitabbarcontroller,Ios,我想制作一个应用程序,它使用一个uitabarcontroller,类似于iPhone和iPodtouch的Twitter应用程序。(蓝色指示灯表示未读,滑动箭头表示在内容视图之间切换) 有没有一个简单的方法可以做到这一点?有开源代码吗 编辑: 我加了一笔赏金。我正在寻找一个能够跨设备、在iOS 4和iOS 5上工作的答案 编辑: 我弄乱了我的原始代码,我找到了一个简单的解决方案。我在我的动画代码中为iOS 5添加了以下检查: // iOS 5 changes the subview hier
// 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]);
不过,我仍然坚持悬赏,以防我有机会在答案中找到一些有用的东西。我将创建一个标准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]
}
}
下面是创建箭头的方法
然后按照拉斐尔的回答去做 虽然这是一篇老化的帖子,但我想我会插入一个无人提及的GitHub项目,他们已经很好地重新创建了Twitter风格的选项卡栏,下面是链接: 项目位于名为“CustomTabBar”的子文件夹中,更多信息可在此处找到: 是我自定义twitter样式选项卡栏的基础,它在iOS 4和iOS 5中工作: 每个选项卡视图控制器应对选项卡图像实施以下方法:
- (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制作了一个类似的应用程序,结果证明它比你想象的要简单 首先,在我的
应用程序IDFinishLaunching:
方法中,我添加了imageview,其中包含指针或箭头的图像,宽度为64,屏幕宽度为320,我在选项卡栏中有5个选项卡。如果您认为您的项目将有动态选项卡,然后只需相应地更改imageview的宽度(如下图所示),也可以计算它
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;
[uiview beginanimation:nil context:nil];
CGRect rect = tabBarpointerImageView.frame;
rect.origin.x = rect.size.width * tabbarcontroller.selectedIndex;
tabBarpointerImageView.frame = rect;
[uiview commitanimations];
然后在选项卡栏控制器的委托方法中
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
只需使用动画块来设置指针移动的动画,如下所示
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;
[uiview beginanimation:nil context:nil];
CGRect rect = tabBarpointerImageView.frame;
rect.origin.x = rect.size.width * tabbarcontroller.selectedIndex;
tabBarpointerImageView.frame = rect;
[uiview commitanimations];
附言。
如果某些拼写不正确,很抱歉。好的。我会调查的。欢迎提供更多信息。很好的示例代码,但是您如何更改选项卡的形状?在twitter应用程序中,顶部是圆形的,底部是方形的。可能需要将其包装在
[UIView beginAnimation]
和[UIView Committeanimations]
中,以使其四处滑动。我已经将此作为起点-请参阅我对问题的编辑,以获得iOS5更新。很棒的链接,但加载需要很长时间。看起来我需要为每个选项卡添加代码。。。不是我想做的。您可能可以通过向视图控制器询问其选项卡栏图像来简化它,否?@Moshe这就是我在开始时链接的BCTabBarController版本的工作方式。视图控制器使用iconImageName
方法确定每个选项卡图像。您可以选择将方法((UIImage*)tabBarController:(jhtabarController*)tabBarController backgroundImageForTabAtIndex:(NSInteger)index
)放入应用程序委托中,以告诉tab-bar控制器要将哪个图像用作该选项卡的背景图像。@如果您使用此代码(无论谁获得赏金),请单击此处我可以帮你实现它。如果你想要更详细的答案,可以开始聊天。谢谢你的好意。目前,根据我的第二次编辑,我有一个可以在这两个方面工作的工作实现。我想我会让bounty运行它的程序,然后添加我自己完整的工作代码示例。实际上,我联系了这个控件的开发人员,但最终没有使用它,因为它在推送时没有实现HidesBottomBar。