看看下面的截图。我想知道如何在用户界面中获得半透明外观。我怎样才能开始使我的 UI 看起来相似?
最佳答案
这是 iOS 8 中引入的新 API。Apple 的文档 lives here , 和 this question包含一些示例代码。注意 - 我在最近的两个测试版中遇到了困难,所以要为一些视觉错误做好准备。
对于 iOS 7,有一个简单(且可容忍)的 hack,可让您操纵 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
关于ios - 在 iOS 中实现透明外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24344868/