[英]TapGesture doesn't work under tabBar
I have a "classic app" with 3 ViewController and a tabBar that I use to change ViewController. 我有一个带有3个ViewController的“经典应用”和一个用于更改ViewController的tabBar。
On my first ViewController, I have a button that display a UIView on all the screen, so I hide tabBar with this setTabBarVisible func : 在我的第一个ViewController上,我有一个在所有屏幕上都显示UIView的按钮,因此我使用setTabBarVisible函数隐藏了tabBar:
extension UIViewController
{
func setTabBarVisible(visible: Bool, animated: Bool)
{
//* This cannot be called before viewDidLayoutSubviews(), because the frame is not set before this time
// bail if the current state matches the desired state
if (isTabBarVisible == visible) { return }
// get a frame calculation ready
let frame = self.tabBarController?.tabBar.frame
let height = frame?.size.height
let offsetY = (visible ? -height! : height)
// zero duration means no animation
let duration: TimeInterval = (animated ? 0.3 : 0.0)
// animate the tabBar
if frame != nil
{
UIView.animate(withDuration: duration)
{
self.tabBarController?.tabBar.frame = frame!.offsetBy(dx: 0, dy: offsetY!)
return
}
}
}
var isTabBarVisible: Bool
{
return (self.tabBarController?.tabBar.frame.origin.y ?? 0) < self.view.frame.maxY
}
}
That's working, the tabBar is hidden and I see all my UIVIew. 可以了,tabBar被隐藏了,我看到了所有的UIVIew。 The problem is, I have a UILabel at bottom of the UIView (at the place I usually display the tabBar), and I can't use my TapGesture on my UILabel, nothing is happening. 问题是,我在UIView的底部有一个UILabel(在我通常显示tabBar的位置),并且我无法在UILabel上使用TapGesture,所以什么也没发生。 (if I display the label somewhere else the UITapGesture works good.) (如果我在其他地方显示标签,则UITapGesture效果很好。)
I tried to set zPosition of my tabBar to 0 and zPosition of my UIView to 1 but that's doesn't work either. 我试图将我的tabBar的zPosition设置为0,将UIView的zPosition设置为1,但这也不起作用。
How can I get my label clickable at bottom of my view? 如何在视图底部使标签可点击?
make sure is true 确保是真的
label.isUserInteractionEnabled = true label.isUserInteractionEnabled = true
Check UILabel.isUserInterration = enable 检查UILabel.isUserInterration =启用
Make sure that when you hide tabbar, perticular view controller Under bottom bar property is unselect . 确保隐藏标签栏时,取消选择“垂直视图控制器在底部栏下”属性。 See atteh imnage. 参见atteh imnage。
You can try with programatically also like 您可以通过编程方式尝试
ViewController.edgesForExtendedLayout = UIRectEdge.top
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.