Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIVibrancyEffect dimmed on device, vibrant in Simulator

I'm experiencing poor rendering of vibrancy effect on my iPhone 6.

This is how it looks: simulator vs. device

I've checked the value of UIAccessibilityIsReduceTransparencyEnabled() and it returns false on both device and in the simulator.

The code for the background image, the effects and a containerView that I add every other elements to looks like this:

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)
    }
}
like image 388
MartinHN Avatar asked Mar 07 '15 11:03

MartinHN


1 Answers

It is perhaps that UIAccessibilityDarkerSystemColorsEnabled() returns true for your iPhone 6 or iPhone 6 plus, so it appears darker.

To disable it, go to Settings -> General -> Accessibility -> Increase Contrast -> Darken Colours, toggle it off should work.

Edit

As stated in the document 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.

We should use images with a rendering mode of UIImageRenderingModeAlwaysTemplate to make UIImageView objects update automatically. Applying this makes the UIVibrancyEffect vibrant on iPhone device.

like image 186
gabbler Avatar answered Nov 06 '22 12:11

gabbler