本文介绍了Twitter-esque UITabBarController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个使用UITabBarController的应用程序,该应用程序类似于iPhone和iPod touch的Twitter应用程序。 (用于未读和滑动箭头的蓝灯用于在内容视图之间切换)。

I'd like to make an app that uses a UITabBarController that is similar to the one in the Twitter app for iPhone and iPod touch. (Blue light for unread and sliding arrow for switching between content views).

有没有一种简单的方法可以做到这一点?任何开源代码?

Is there an easy way to do this? Any open source code?

修改:

我添加了赏金。我正在寻找适用于各种设备以及iOS 4和iOS 5的解决方案。

I've added a bounty. I'm looking for an answer that works across devices and on iOS 4 and iOS 5.

编辑:

我弄乱了原始代码,发现了一个简单的解决方案。我在动画代码中为iOS 5添加了以下检查:

I've messed with my original code and I found a simple solution. I've added the following check, for iOS 5 in my animation code:

//  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]);

尽管如此我仍然坚持赏金,以防我有机会找到适用于答案。

Still holding out on the bounty though, in case I get a chance to find something that works in the answers.

推荐答案

我会创建标准UITabBarController的子类,并为蓝灯和滑动箭头添加几个子视图。不应该太难实现。

I would create a subclass of the standard UITabBarController and add a couple of subviews for the blue light and the sliding arrow. Shouldn't be too hard to accomplish.

编辑:
这里有一些关于你的子类应该包含的内容的想法。我甚至都不知道这段代码是否会编译。

Here's an idea of some of the stuff that should go in your subclass. I don't even know if this code will compile.

- (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]
    }
}

这篇关于Twitter-esque UITabBarController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 07:14