ios - 如何在屏幕顶部附近显示带有触摸的导航栏?

标签 ios uinavigationcontroller uinavigationbar

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

我尝试添加一个与背景颜色相同的按钮,然后在触摸它时显示导航栏,但这似乎不起作用。

另外,我要如何做一个演示才能向用户展示这是可行的?谢谢!

最佳答案

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

  • (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)隐藏导航栏

{

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

关于ios - 如何在屏幕顶部附近显示带有触摸的导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10990963/

相关文章:

ios - 无法在最新 Xcode 版本的 Swift 中设置导航栏字体

swift - 如何将 View Controller 推送到生成的导航层次结构中

ios - 为什么 iOS 11 中导航 backBarButtonItem 的位置出现了三个按钮?

ios - 为什么弹出 UIViewController 会改变 navigationItem 的 titleTextAttributes?

ios - 在 iOS 应用中添加 revmob 广告时出现构建错误

iphone - 复制文件到不同的目录

ios - UIViewController 动画转换在 iOS8 中失败

ios - 续订 Push 证书并保持当前 App Store 应用正常运行

ios - 推送到新 View 时 UIButton 未突出显示

swift - Nav BarItem 返回上一个 View