简体   繁体   中英

How can I have a UIView slide out from under a 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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM