查看以下屏幕截图。我想知道如何在用户界面中获得半透明的外观。我怎样才能开始让我的UI看起来相似?
答案 0 :(得分:1)
这是iOS 8中引入的新API.Apple的文档lives here和this question包含一些示例代码。注意 - 我在最后两个测试版中一直遇到困难,所以要为一些视觉错误做好准备。
对于iOS 7,有一个简单(和容忍)的黑客攻击,让你可以操纵UIToolBar来实现类似的效果,尽管控制力较弱。有一个开源项目here可以抽象一点。
编辑 - 如果你使用Swift,这里有一些示例代码:
// change .ExtraLight to .Light or .Dark to change the color of the blurred view
let blurEffect = UIBlurEffect(style: .ExtraLight)
let backgroundView = UIVisualEffectView(effect: blurEffect)
backgroundView.frame = self.bounds
backgroundView.autoresizingMask = .FlexibleWidth | .FlexibleHeight
self.addSubview(backgroundView)
let vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(forBlurEffect: blurEffect))
vibrancyView.frame = self.bounds
vibrancyView.autoresizingMask = .FlexibleWidth | .FlexibleHeight
backgroundView.contentView.addSubview(vibrancyView)
// Now, add your subviews to the vibrancyView.contentView
// The effects are a bit tricky to get right with the color of your subviews, but here's how it's supposed to work:
// - UIColor.whiteColor() shows up as pure, solid, (non-translucent) white
// - UIColor.grayColor() shows up as essentially no change in the brightness of the underlying view, just blurred and vibrant