Andre Cytryn
Andre Cytryn

Reputation: 2705

How to show a UIView on top of UINavigationBar

Does anyone have any elegant solution to move UIView in front of a UINavigationBar?

I want the following to happen:

1 - click the green button

2 - green button and blue view slide up to UINavigationBar

3 - green button stay on top of UINavigationBar

enter image description here

Upvotes: 1

Views: 1011

Answers (1)

Weaverfish
Weaverfish

Reputation: 930

Not the most elegant solution, but I think you will need to remove the button from it's current view hierarchy and add it to the navigation controller view.

e.g.

- (void)buttonPress:(UIButton *)sender {

    [UIView animateWithDuration:0.3 animations:^{
        [sender removeFromSuperview];
        [self.navigationController.view addSubview:sender];
        [sender setFrame:CGRectMake(sender.frame.origin.x, self.navigationController.navigationBar.frame.origin.y, sender.frame.size.width, sender.frame.size.height)];
    }];

}

Upvotes: 1

Related Questions