检测轻击以显示/隐藏UINavigationBar [英] Detecting tap to Show/hide UINavigationBar

查看:68
本文介绍了检测轻击以显示/隐藏UINavigationBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对iPhone开发有点新鲜,还没有做任何事情。
我的视图层次结构如下:

I am kinda new to iPhone development and haven't done anything yet envolving touches. My view hierarchy like this:


UIView - UIImageView - UIScrollView - CustomView


如何检测用户是否已在屏幕上的任何位置点击可以相应地显示/隐藏导航栏?我不需要在我的CustomView的用户交互,但我想忽略UIScrollView的用户只是想拖动它时触摸。

How do I detect if the user has tapped anywhere on the screen so I can show/hide the navigation bar accordingly? I don't need user interaction on my CustomView but I'd like to ignore touches on the UIScrollView when the user just wants to drag it.

我可以已经显示/使用以下命令从我的视图控制器中隐藏导航栏:

I can already show/hide the navigation bar from my view controller programatically using:

[self.navigationController setNavigationBarHidden:YES animated:YES];

提前感谢!

推荐答案

您可以使用UIView中的touchesBegan方法来检测水龙头,因此您必须为viewcontroller的视图创建一个自定义子类 UIView 你想检测水龙头。然后你必须使用代理来发送你的视图的控制器,这样它可以隐藏 navigationBar

You can use the method touchesBegan in UIView to detect the tap, so you will have to have a custom subclass of UIView for the viewcontroller's view that you would like to detect taps on. Then you'll have to use the delegate to message your view's controller so it can hide the navigationBar.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSUInteger numTaps = [[touches anyObject] tapCount];
    if (numTaps == 1)
    {
        [delegateController tapDidOccur];  
    }
}

这篇关于检测轻击以显示/隐藏UINavigationBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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