长话短说,如果我的 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/