ios - 如何使用 hitTest :withEvent: to send touches from my nav bar to the underlying view under certain circumstances?

标签 ios objective-c uiview uinavigationcontroller uinavigationbar

长话短说,如果我的 UINavigationBar 的 alpha 设置为 0,我希望所有触摸都转到底层 View (从带有导航栏的 View Controller 的角度来看,这只是是 self.view )。如果是 1.0,我希望它保留它们。

我对 UINavigationBar 进行了子类化,并且尝试覆盖 hitTest:withEvent:,但我真的很困惑我在做什么,并且搜索没有什么帮助。

我如何告诉它,“如果 alpha 为 0,则将触摸发送到 self.view,否则保留在导航栏上”?

最佳答案

您需要将 View 的引用发送到导航栏中,将其设置为名为 behindView 或其他内容的属性。

if(self.alpha == 0.0f)
{
    return behindView;
}
return [super hitTest:point withEvent:event];

另一种方法是重写pointInside:withEvent:,如下所示:

if(self.alpha == 0.0f)
{
    return NO;
}
return [super pointInside:point withEvent:event];

关于ios - 如何使用 hitTest :withEvent: to send touches from my nav bar to the underlying view under certain circumstances?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18092528/

相关文章:

ios - 如何在另一个 View Controller 的顶部滑动 View Controller ?

objective-c - 如何将 UITableViewController 添加到 XCode4 中 UITabViewController 上的 UINavigationController?

iPhone 自定义 ui 组件

iOS 13 移除 UIView 以模拟状态栏背景

ios - 我可以在 IOS 中获取下载的 M4A、MP3 文件吗?

ios - Swift:无法下标类型为 '[UIViewController]?' 的值

objective-c - 在 Swift 2 中子类化 AFHTTPSessionManager 的正确方法

objective-c - 如何在 Objective C 中将 float 转换为 int?

ios - 以编程方式调用 UIView 的点击手势

ios - telprompt - 我可以获得通话时长吗?