在透明UITabBar上的黑色背景
我想为我的UITabViewController
制作一个模糊的背景UITabBar
,并且这个想法是让它变得模糊和透明,以便下面的视图可以看到滚动。
不幸的是,我不能让我的生活得到标签栏是透明的。 不pipe我做什么,总是有一些黑色背景的标签栏,防止底层视图控制器显示。
如果我将UITabBar
的alpha值改为低,我可以看到tableview确实在它后面,但是你可以看到UITabBar
有一些背景,阻止了tableview完全显示(而且我不'要禁止button的项目是不可见的,只是标签栏背景)。
怎么会这样?
在自定义标签栏的视图没有加载我有:
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
…是的这是过度的,但我想尝试一切。
有什么想法做什么?
使UITabBar透明
为其backgroundImage
分配一个清晰的图像。 您可以使用1×1的clear.png,或以编程方式创build一个:
self.backgroundImage = UIImage.imageWithColor(UIColor.clearColor())
这将使UITabBar
透明:
添加模糊效果
插入一个UIVisualEffectView
作为最后面的子视图。
let frost = UIVisualEffectView(effect: UIBlurEffect(style: .Light)) frost.frame = self.bounds self.insertSubview(frost, atIndex: 0)
这将插入一个UIBlurEffect
(霜):
例
- 将选项卡栏控制器的
UITabBar
的自定义类设置为FrostyTabBar
。 - 你有几个选项来提供一个
clearColor
图像。 您可以创build一个alpha为0的clear.png图像。 这里描述一个编程优雅的解决scheme。 - 如果使用clear.png ,则将其分配给属性检查器中的背景图像 :
- 在Interface Builder中,selectStyle : Default & Translucent 。
- 一旦你用
UIVisualEffectView
控制了背景模糊,你可以依次提供你所需要的任何UIVisualEffect
。
整个FrostyTabBar
类看起来像这样:
import UIKit class FrostyTabBar: UITabBar { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) let frost = UIVisualEffectView(effect: UIBlurEffect(style: .light)) frost.frame = bounds frost.autoresizingMask = .flexibleWidth insertSubview(frost, at: 0) } }
►在GitHub上find这个解决scheme,并在Swift Recipes上find 1×1的clear.png。
我find了一个完美的解决scheme,你只需要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 } } } } }
- 迅捷每周提示— IV
- ios8 xcode如何删除UIKeyboard上的QuickType(自动完成/自动build议)
- 如何调用UIAccessibilityRequestGuidedAccessSession()
- 限制iphone应用程序只安装在具有Retina显示器的设备(iphone 4 / 4S)
- Swift 3 Decimal,NSDecimal和NSDecimalNumber
- 通过自定义URL方案深入链接到eBay iOS应用程序?
- WatchKit应用程序的部署目标必须等于iOS 8.2(8.3)?
- 根据预处理器macros值更改基本URL
- 如何从Popover中的button中解除UIPopover