ios - UIVibrancyEffect 在设备上变暗,在模拟器中充满活力

标签 ios iphone swift ios8

我的 iPhone 6 上的活力效果呈现不佳。

它是这样的: simulator vs. device

我检查了 UIAccessibilityIsReduceTransparencyEnabled() 的值并且它在设备和模拟器中都返回 false。

背景图片、效果和我添加所有其他元素的 containerView 的代码如下所示:

import Foundation
import UIKit
import PureLayout

class BackgroundImageView : UIView {
    let bgImage = UIImageView(forAutoLayout: ())
    var blurView:UIVisualEffectView!
    var vibrancyView:UIVisualEffectView!

    var containerView: UIView? = nil {
        willSet(container) {
            vibrancyView.contentView.addSubview(container!)
        }
    }

    init(imageName: String) {
        super.init()

        let screenSize: CGRect = UIScreen.mainScreen().bounds

        bgImage.image = UIImage(named: imageName)
        // Scale relative to the size of the iPhone 6 Plus: http://martinnormark.com/smooth-transition-from-launch-image-to-view-controller-in-ios/
        bgImage.transform = CGAffineTransformMakeScale(screenSize.width / 414, screenSize.height / 736)

        self.addSubview(bgImage)

        let blurEffect = UIBlurEffect(style: .Dark)
        self.blurView = UIVisualEffectView(effect: blurEffect)
        self.blurView.setTranslatesAutoresizingMaskIntoConstraints(false)

        self.addSubview(blurView)

        let vibrancyEffect = UIVibrancyEffect(forBlurEffect: blurEffect)
        vibrancyView = UIVisualEffectView(effect: vibrancyEffect)
        vibrancyView.setTranslatesAutoresizingMaskIntoConstraints(false)

        blurView.contentView.addSubview(vibrancyView)
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override func updateConstraints() {
        super.updateConstraints()

        bgImage.autoCenterInSuperview()
        containerView?.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsetsZero)
        blurView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsetsZero)
        vibrancyView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsetsZero)
    }
}

最佳答案

可能是 UIAccessibilityDarkerSystemColorsEnabled() 为您的 iPhone 6 或 iPhone 6 plus 返回 true,所以它看起来更暗。

要禁用它,请转到“设置”->“通用”->“辅助功能”->“增加对比度”->“变暗颜色”,将其关闭应该可以。

编辑

如文档中所述 UIVibrancyEffect .

The vibrancy effect is color dependent. Any subviews that you add to the contentView must implement the tintColorDidChange method and update themselves accordingly. UIImageView objects with images that have a rendering mode of UIImageRenderingModeAlwaysTemplate as well as UILabel objects will update automatically.

我们应该使用渲染模式为 UIImageRenderingModeAlwaysTemplate 的图像来使 UIImageView 对象自动更新。应用它可以使 UIVibrancyEffect 在 iPhone 设备上充满活力。

关于ios - UIVibrancyEffect 在设备上变暗,在模拟器中充满活力,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28914415/

相关文章:

iphone - 通过在iphone sdk中解析获取城市名称

ios - 推 segue 过渡动画是断断续续的

ios - iOS 锁定屏幕中的播客 "skip"按钮

ios - 如何拉伸(stretch)使用 UIBezierPath 绘制的线?

iphone - 将 JSON 数据放入 NSURL

iphone - 生产应用程序中的 iOS 核心数据对象模型更改

javascript - 使用 JavascriptCore 和 JSContext 从 javascript 调用 native Swift 代码

swift - macOS 应用程序,例如 macOS 上的 Photos.app

objective-c - 跨平台 iOS/Mac OS X Objective-C 开发?

iphone - 将常量语言设置为 CLPlacemark 实例类