【发布时间】:2018-05-24 10:54:43
【问题描述】:
我有一个带有 3 个 ViewController 和一个用于更改 ViewController 的 tabBar 的“经典应用程序”。
在我的第一个 ViewController 上,我有一个在整个屏幕上显示 UIView 的按钮,所以我用这个 setTabBarVisible func 隐藏了 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
}
}
这行得通,tabBar 被隐藏了,我可以看到我所有的 UIVIew。 问题是,我在 UIView 的底部有一个 UILabel(在我通常显示 tabBar 的地方),我不能在我的 UILabel 上使用我的 TapGesture,什么也没有发生。 (如果我在其他地方显示标签,UITapGesture 效果很好。)
我尝试将 tabBar 的 zPosition 设置为 0,将 UIView 的 zPosition 设置为 1,但这也不起作用。
如何让我的标签在视图底部可点击?
【问题讨论】:
-
确保您的标签在您的视图范围内。尝试将视图的 clipsToBounds 属性设置为 true。如果标签被剪裁,则意味着它超出了视图范围,因此不会将触摸传递给它。
-
我在 UIView 的 viewDidLoad() 中尝试使用“self.clipsToBounds = true”,但我仍然可以看到我的 UILabel,所以我想这不是问题所在。还是谢谢
-
我找到了解决方案。这与我的视图范围有关,我正在将该视图添加到另一个视图中,而另一个视图的高度不足以容纳我所有的新视图。