如何在屏幕顶部附近显示带有触摸的导航栏? [英] How to show Navigation Bar with Touch Near Top of Screen?

查看:29
本文介绍了如何在屏幕顶部附近显示带有触摸的导航栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是首先隐藏导航栏,然后如果用户触摸屏幕顶部(它应该在的位置)导航栏将显示大约一两秒钟然后消失.

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!

推荐答案

先在app的delegate中隐藏导航栏,然后到要添加触摸事件的view controller,使用这两个方法:

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

    -(void)hideNavigationBar

    {

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

    }

    这篇关于如何在屏幕顶部附近显示带有触摸的导航栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆