我正在尝试为我的UITabViewController
做一个模糊的背景作为UITabBar
,我的想法是让它变得模糊和透明,这样下面的视图就可以滚动过去。
不幸的是,我无论如何也不能让标签栏变得透明。不管我怎么做,标签栏总是有一些黑色的背景,阻止底层视图控制器显示出来。
如果我将UITabBar
的alpha更改为较低的值,我可以看到tableview确实在它的后面,但是您可以看到UITabBar
有某种背景,这阻止了tableview完全显示出来(我不想让按钮项不可见,只显示选项卡栏背景)。
这怎么可能呢?
在自定义选项卡栏的视图中,我有:
self.tabBar.translucent = true
self.tabBar.alpha = 0.3
self.tabBar.backgroundColor = UIColor.clearColor().colorWithAlphaComponent(0.0)
self.tabBar.layer.backgroundColor = UIColor.clearColor().colorWithAlphaComponent(0.0).CGColor
self.tabBar.backgroundImage = nil
self.tabBar.shadowImage = nil
在AppDelegate中,我有:
UITabBar.appearance().barTintColor = UIColor.clearColor()
UITabBar.appearance().tintColor = kColorAccent
UITabBar.appearance().translucent = true
UITabBar.appearance().translucent = true
UITabBar.appearance().backgroundColor = UIColor.clearColor()
UITabBar.appearance().backgroundImage = nil
UITabBar.appearance().layer.backgroundColor = UIColor.clearColor().CGColor
UITabBar.appearance().shadowImage = nil
...yeah,这是多余的,但我想尝试所有的方法。
你有什么建议吗?
发布于 2016-05-16 22:14:52
我找到了一个完美的解决方案,您只需要子类化UITabBar,然后执行以下操作来清理那个恼人的视图
class MainTabBar: UITabBar {
var cleanDone = false
override func layoutSubviews() {
super.layoutSubviews()
self.deleteUnusedViews()
}
func deleteUnusedViews() {
if !self.cleanDone {
var removeCount = 0
for (_, eachView) in (self.subviews.enumerate()) {
if NSStringFromClass(eachView.classForCoder).rangeOfString("_UITabBarBackgroundView") != nil {
eachView.removeFromSuperview()
removeCount += 1
}
if NSStringFromClass(eachView.classForCoder).rangeOfString("UIImageView") != nil {
eachView.removeFromSuperview()
removeCount += 1
}
if removeCount == 2 {
self.cleanDone = true
break
}
}
}
}
}
https://stackoverflow.com/questions/33819852
复制相似问题