Pregunta

What I want to do is have the navigation bar hidden at first, and then if the user touches the top of the screen (where it should be) the navigation bar will show for about 1 second or two and disappear.

I tried adding a button that was the same color as the background and then when that is touched show the navigation bar, but that doesn't seem to be working.

Also how would I do a demo so I could show the user that this works? Thanks!

¿Fue útil?

Solución

first hide the navigation bar in the app delegate.then come to the view controller where you want to add the touch event,and use these two methods:

  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

//mouseSwiped = NO;
CGPoint touchPoint;
//CGPoint touchPointNavigationBar;
UITouch *touch = [touches anyObject];
touchPoint=[touch locationInView:self.view];
if (self.navigationController.navigationBarHidden==YES) {
    if (touchPoint.y<50) {
        self.navigationController.navigationBarHidden=NO;
        timer=[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(hideNavigationBar) userInfo:nil repeats:NO];  
        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    }
}

}

-(void)hideNavigationBar

{

self.navigationController.navigationBarHidden=YES;
if ([timer isValid]) {
    [timer invalidate];
    return;
}

}

Otros consejos

This is one of the way to get your output. I am explaning this code line by line, which will help you better.

1]

Add one button at the top of your view, and add any transparent background image to that button and write self.navigationController.navigationBarHidden = YES; in viewDidLoad.

// this will hide your navigation bar, n now u can create your own custom Navigation Bar.

2]

Now take sepatare UIView in xib , named it as a view2 and connect with respective IBOutlet.

Take respective IBOutlets and IBAction and Two Functions then connect to view and button.

The code below, goes into .h file >>>>>

IBOutlet UIButton *btnHideNShow; // Connect this to button

IBOutlet UIView *viewTemp; // connect this to View

-(IBAction)btnHideNShowAction:(id)sender; // Connect this to Button

-(void)fun1;

-(void)fun2;

3]

Now the code below goes into .m file >>>>

-(IBAction)btnHideNShowAction:(id)sender{

btnHideNShow.hidden = YES;
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(fun1) userInfo:nil repeats:NO];

}

-(void)fun1{

viewTemp.frame = CGRectMake(0, 0, 320, 59);
[self.view addSubview:viewTemp];


[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(fun2) userInfo:nil repeats:NO];

}

-(void)fun2{

[viewTemp removeFromSuperview];
btnHideNShow.hidden = NO;

}

> You can customize this view as per your requirment.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top