使用UITabBarController添加持久性UIView

时间:2011-03-16 22:03:20

标签: iphone objective-c uiview uitabbarcontroller depth

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

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

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?

1 个答案:

答案 0 :(得分:2)

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

您可以向aboutView实现添加代码,以便在视图显示时为其设置动画。

我在弹出视图中执行类似这样的操作,我希望在标签栏控件下显示。您可以在aboutView实现上的didMoveToSuperview消息中添加一些代码:

- (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添加到所选视图控制器的视图中时,它会自动设置动画。