如何将 UIView 滑动到 UITabBar 的正上方

发布于 2024-12-18 13:23:32 字数 794 浏览 2 评论 0原文

我有一个 UIView,我想从 UITabBar 后面滑动到它的正上方。

这是行不通的。我的观点没有出现。

- (void)showNotificationBar
{   
    CGRect frame = CGRectMake(0, 500, 320, 32);
    frame.origin.y = CGRectGetMaxY(self.parentViewController.tabBarController.tabBar.frame) - frame.size.height;
    notificationBar.frame = frame;

    [self.parentViewController.tabBarController.tabBar.superview insertSubview:notificationBar 
                                                                  belowSubview:self.parentViewController.tabBarController.tabBar];

    [UIView animateWithDuration:0.5 animations:^{
        CGRect frame = notificationBar.frame;
        frame.origin.y = CGRectGetMaxY(self.parentViewController.tabBarController.tabBar.frame);
        notificationBar.frame = frame;
    }];
}

I have a UIView that I want to slide from behind a UITabBar to be position right on top of it.

This doesn't work. My view does not appear.

- (void)showNotificationBar
{   
    CGRect frame = CGRectMake(0, 500, 320, 32);
    frame.origin.y = CGRectGetMaxY(self.parentViewController.tabBarController.tabBar.frame) - frame.size.height;
    notificationBar.frame = frame;

    [self.parentViewController.tabBarController.tabBar.superview insertSubview:notificationBar 
                                                                  belowSubview:self.parentViewController.tabBarController.tabBar];

    [UIView animateWithDuration:0.5 animations:^{
        CGRect frame = notificationBar.frame;
        frame.origin.y = CGRectGetMaxY(self.parentViewController.tabBarController.tabBar.frame);
        notificationBar.frame = frame;
    }];
}

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

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

发布评论

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

评论(3

浮光之海 2024-12-25 13:23:32

像这样初始化frame.origin.y

frame.origin.y = self.tabBarController.tabBar.frame.origin.y;

在动画块中,如下设置:

frame.origin.y -= frame.size.height;

Initialize frame.origin.y like this:

frame.origin.y = self.tabBarController.tabBar.frame.origin.y;

In the animations block, set it like this:

frame.origin.y -= frame.size.height;
哎呦我呸! 2024-12-25 13:23:32

如果您希望它在每个视图中显示,您可以这样做:要么将其显示在每个视图的底部,要么将其显示在应用程序的窗口中。我个人更喜欢第二种方法,因为它有助于避免重复代码:

CGFloat notificationBarHeight = 40.0f;
UIView *notificationBar = [[UILabel alloc]initWithFrame:CGRectMake(0, self.tabBarController.tabBar.frame.origin.y - notificationBarHeight, 320, notificationBarHeight)];
[self.window insertSubview:notificationBar atIndex:[[self.window subviews]count]];

If you want it to show in every view, you could do to things: either show it at the bottom of every view or show it in the application's window. I personally like this second approach better because it helps avoiding duplicate code:

CGFloat notificationBarHeight = 40.0f;
UIView *notificationBar = [[UILabel alloc]initWithFrame:CGRectMake(0, self.tabBarController.tabBar.frame.origin.y - notificationBarHeight, 320, notificationBarHeight)];
[self.window insertSubview:notificationBar atIndex:[[self.window subviews]count]];
再浓的妆也掩不了殇 2024-12-25 13:23:32

[self.view insertSubview:notificationView atIndex:1];为我工作...

[self.view insertSubview:notificationView atIndex:1]; worked for me...

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