iphone - 使用 UITabBarController 添加持久化 UIView

标签 iphone objective-c uiview uitabbarcontroller depth

我有一个使用 UITabBarController 的应用程序,我有另一个 View 需要从选项卡栏控件后面向上滑动,但在选项卡栏内容的前面。如果这还不清楚,请想象一个广告在一个选项卡式应用程序中向上滑动,该应用程序出现在除选项卡栏按钮之外的所有内容的前面。

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

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?

最佳答案

您需要在 UITableBarController 中将 aboutView 添加为当前事件 View Controller 中 View 的 subview .您可以通过 selectedViewController 访问该 View 属性(property)。

您可以将代码添加到 aboutView 实现中,以便在 View 出现时为其设置动画。

我在一个弹出 View 中做了类似的事情,我想在选项卡栏控件下显示。您可以向 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 添加到所选 View Controller 的 View 时,它会自动进行动画处理。

关于iphone - 使用 UITabBarController 添加持久化 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5332396/

相关文章:

iphone - NSTimer for UITableviewcell 类似于世界时钟应用程序

c - "long long"是什么数据类型?

ios - 带有 ImageView 、2 个标签、按钮的自动布局 - 标签在旋转后消失

ios - UITableView 中的 insertRowsAtIndexPaths 添加重复行

iphone - iOS UIView 动画问题

ios - MKUserTrackingBarButtonItem 功能,但不在一个愚蠢的条形按钮中

iphone - 为什么在 iPad 上删除后需要 CoreData forceFetch 而在 iPhone 上则不需要?

ios - 保留 mask UIView 的阴影

iphone - 如何检查是否设置了自定义委托(delegate)?

ios - 如何在 iOS 上的 ImageView 下方添加阴影效果?