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

最佳答案

这是iOS 8中引入的新API。Apple的文档lives herethis question包含一些示例代码。注意-在上两个测试版中,我一直遇到困难,因此请准备一些可视化的bug。

对于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/

10-14 19:59
查看更多