Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add UIView over navigation bar?

I need overlay UINavigationBar with UIView like here

http://screencast.com/t/ZKXNFcAzVu

Is there a way to do this except using custom UIView with button back as nav bar?

like image 631
Andrii Tishchenko Avatar asked Jan 09 '13 09:01

Andrii Tishchenko


3 Answers

You can add a subview to the base view of the Application

[[[UIApplication sharedApplication] keyWindow] addSubview:vMyCustomUIView];

To make sure it is only shown when your view controller is visible you could add and remove it in the viewDidAppear and viewDidDisappear delegate methods. Here is an example that would show a blue box overlapping them.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.    
    vTestView = [[UIView alloc] initWithFrame:CGRectMake(10.0f,
                                                         10.0f,
                                                        100.0f,
                                                        100.0f)];
    vTestView.backgroundColor = [UIColor blueColor];
}


-(void)viewDidAppear:(BOOL)animated
{
    [[[UIApplication sharedApplication] keyWindow] addSubview:vMyCustomUIView];
}
-(void)viewDidDisappear:(BOOL)animated
{
    [vMyCustomUIView removeFromSuperview];
}
like image 156
Martin Belcher - AtWrk Avatar answered Oct 16 '22 15:10

Martin Belcher - AtWrk


Use the method :

- (void)bringSubviewToFront:(UIView *)view

So in your case that will be :

[navigationBar addSubview:myRibbon];
[navigationBar bringSubviewToFront:myRibbon];

Also don't forget that with this way, your ribbon won't be showed completely except if you do this :

navigationBar.clipsToBounds = NO;
like image 43
delannoyk Avatar answered Oct 16 '22 13:10

delannoyk


I hide NavigationBar and added UIView instead. It looks the same as Navbar. then add more one UIView with red bookmark. Beside it give possibility to animate bookmark on touch separately.

If I added bookmark this way: [navigationBar addSubview:myRibbon]; it was hidden on half of size

like image 43
Andrii Tishchenko Avatar answered Oct 16 '22 15:10

Andrii Tishchenko