使用 UITabBarController 添加持久 UIView

发布于 2024-10-22 05:25:28 字数 928 浏览 2 评论 0原文

我有一个使用 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 放在其他内容前面?

I have an app using a UITabBarController, and I have another view that needs to slide up from behind the tab bar controls, but in front of the tab bar's content. If that's not clear, imagine an advertisement sliding up in a tabbed app that appears in front of everything except for the tab bar buttons.

So far I have code that looks something like this, but I'm willing to change it if there's a better way to do this...

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

Currently aboutView is a subclass of UIView and sits at its starting position at the bottom, but it hides the tabBarController. How can I change this to let the tabs be on top, but still have the aboutView in front of the other content?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如此安好 2024-10-29 05:25:28

您需要将 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 添加到所选视图控制器的视图时,它会自动动画化。

You need to add the aboutView as a subview of the view in the currently active view controller in the UITableBarController. You can access that view via the selectedViewController property.

You can add code to your aboutView implementation to animate the view when it appears.

I do something like this in a popup view that I want to appear under the tab bar controls. You can add some code to the didMoveToSuperview message on the aboutView implementation:

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

So when your aboutView is added to the selected view controller's view, it automatically animates up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文