如何让 UIView 从 UINavigationBar 下滑出?

发布于 2024-12-17 08:09:34 字数 714 浏览 4 评论 0原文

目前,我正在显示一个 UIView,它从窗口顶部向下滑动到一个位置:

-(void)showNotificationBar
{
    [notificationBar setFrame: CGRectMake(0, 0, 320, 44)];
    [[[UIApplication sharedApplication] keyWindow] addSubview:notificationBar];

    [UIView animateWithDuration:0.5
                          delay:0.0
                        options: UIViewAnimationCurveEaseInOut
                     animations:^{
                         [notificationBar setFrame: CGRectMake(0, 59, 320, 32)];
                     } 
                     completion:^(BOOL finished){
                         NSLog(@"Done!");
                     }];
}

我希望它从 UINavigationBar 下方滑出。现在它从窗口顶部滑动到导航栏的底部。我希望它从导航栏底部滑动以显示自身。现在确切知道该怎么做吗?

Currently I am displaying a UIView that slides down from the top of my window to a position:

-(void)showNotificationBar
{
    [notificationBar setFrame: CGRectMake(0, 0, 320, 44)];
    [[[UIApplication sharedApplication] keyWindow] addSubview:notificationBar];

    [UIView animateWithDuration:0.5
                          delay:0.0
                        options: UIViewAnimationCurveEaseInOut
                     animations:^{
                         [notificationBar setFrame: CGRectMake(0, 59, 320, 32)];
                     } 
                     completion:^(BOOL finished){
                         NSLog(@"Done!");
                     }];
}

I want this to slide out from under my UINavigationBar. Right now it is sliding from the top of the window, to the bottom of my navigation bar. I want it to slide from the bottom of the navigation bar to display itself. Now exactly sure how to do this?

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

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

发布评论

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

评论(2

蔚蓝源自深海 2024-12-24 08:09:34

您将在窗口中所有其他视图的顶部添加 notificationBar。您需要将其添加为导航栏超级视图的子视图,位于导航栏下方。

假设您的 UINavigationBar 位于属性 self.navBar 中。试试这个:

- (void)showNotificationBar
{
    CGRect frame = CGRectMake(0, 0, 320, 44);
    frame.origin.y = CGRectGetMaxY(self.navBar.frame) - frame.size.height;
    notificationBar.frame = frame;

    [self.navBar.superview insertSubview:notificationBar belowSubview:self.navBar];

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

You're adding notificationBar on top of all other views in your window. You need to add it as a subview of the nav bar's superview, below the nav bar.

Let's say your UINavigationBar is in a property self.navBar. Try this:

- (void)showNotificationBar
{
    CGRect frame = CGRectMake(0, 0, 320, 44);
    frame.origin.y = CGRectGetMaxY(self.navBar.frame) - frame.size.height;
    notificationBar.frame = frame;

    [self.navBar.superview insertSubview:notificationBar belowSubview:self.navBar];

    [UIView animateWithDuration:0.5 animations:^{
        CGRect frame = notificationBar.frame;
        frame.origin.y = CGRectGetMaxY(self.navBar.frame);
        notificationBar.frame = frame;
    }];
}
错爱 2024-12-24 08:09:34

快速浏览一下,您似乎想研究如何“遮罩”图层。
看看这篇文章。

“屏蔽”动画? iPhone SDK

如果您要将下拉菜单隐藏在视图(隐藏视图)下,您可以显示动画,而不会看起来它来自导航栏上方,而是来自导航栏下方。

A quick look at this and it looks like you want to research how to "Mask" a layer.
Take a look at this post.

"Masking" an animation? iPhone SDK

If you were to mask your drop down menu under a view (a hidden view) you could get the animation to show without looking like it came from above your navigation bar, but below it.

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