2011-03-16 60 views
6

我有一个应用程序使用UITabBarController,并且我有另一个视图需要从标签栏控件后面向上滑动,但是在标签栏的内容前面。如果还不清楚,可以想象一个广告在标签栏应用程序中滑动,除了标签栏按钮之外,该应用程序出现在所有内容之前。使用UITabBarController添加持久UIView

到目前为止,我有一些代码看起来像这样,但我愿意去改变它,如果有更好的方法来做到这一点...

tabBarController.viewControllers = [NSArray arrayWithObjects:locationNavController, emergencyNavController, finderNavController, newsNavController, nil]; 

aboutView = [[AboutView alloc] initWithFrame:CGRectMake(0, window.frame.size.height - tabBarController.tabBar.frame.size.height - 37 , 
                 320, window.frame.size.height - tabBarController.tabBar.frame.size.height)]; 


[window addSubview:tabBarController.view]; // adds the tab bar's view property to the window 
[window addSubview:aboutView]; // this is the view that slides in 
[window makeKeyAndVisible]; 

目前aboutView是的UIView的子类,坐在在底部的起始位置,但它隐藏了tabBarController。我怎样才能改变这个让标签在最前面,但仍然有其他内容前的aboutView?

回答

2

您需要将aboutView作为视图的子视图添加到UITableBarController当前活动的视图控制器中。您可以通过selectedViewController属性访问该视图。

您可以将代码添加到aboutView实现中,以便在视图出现时对其进行动画处理。

我在弹出视图中做了这样的事情,我想在标签栏控件下出现。你可以添加一些代码到didMoveToSuperview消息的aboutView实现:

- (void)didMoveToSuperview 
{ 
    CGRect currentFrame = self.frame; 

    // animate the frame ... this just moves the view up a 10 pixels. You will want to 
    // slide the view all the way to the top 
    CGRect targetFrame = CGRectOffset(currentFrame, 0, -10); 

    // start the animation block and set the offset 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; // animation duration in seconds 
    [UIView setAnimationDelegate:self]; 

    self.frame = targetFrame; 

    [UIView commitAnimations]; 
} 

因此,当你aboutView添加到选定的视图控制器的视图,它会自动动画了。

+0

真棒。你是我的英雄 – shulmey 2011-03-17 00:32:05

+0

@ user663222没问题:)很高兴这是有用的。 – RedBlueThing 2011-03-17 00:54:50