微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我的iPhone 6上的振动效果渲染效果不佳.

这就是它的样子:

我检查了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设备上充满活力.

原文地址:https://www.jb51.cc/iOS/333871.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐