ios - 在 iOS 中实现透明外观

标签 ios user-interface transparency

看看下面的截图。我想知道如何在用户界面中获得半透明外观。我怎样才能开始使我的 UI 看起来相似?

Example

enter image description here

最佳答案

这是 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/

相关文章:

ios - Swift UIDevice.currentDevice() 没有编译

ios - 打开模块 'Swift' 的导入文件

ios - 更改 NSFetchedResultsController 的获取请求和重新加载表数据的方法

ios - 从 MPRemoteCommandCenter 丢失 "Now Playing"状态

java - 如何在调整 BufferedImage java 后删除黑色背景

javascript - 如何在 Mithril.js 中叠加弹出 View ?

java - GridBagLayout 行权重

java - setHorizo​​ntalAlignment(CENTER) - CENTER 无法解析为变量

c# - 图片框 图片框

c# - 透明重叠圆形进度条(自定义控件)