I'm experiencing poor rendering of vibrancy effect on my iPhone 6.
我的iPhone 6上的振动效果渲染效果不佳。
This is how it looks:
这就是它的样子:
I've checked the value of UIAccessibilityIsReduceTransparencyEnabled()
and it returns false on both device and in the simulator.
我检查了UIAccessibilityIsReduceTransparencyEnabled()的值,它在设备和模拟器中都返回false。
The code for the background image, the effects and a containerView that I add every other elements to looks like this:
我添加所有其他元素的背景图像,效果和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)
}
}
3 个解决方案
#1
3
It is perhaps that UIAccessibilityDarkerSystemColorsEnabled()
returns true for your iPhone 6 or iPhone 6 plus, so it appears darker.
或许UIAccessibilityDarkerSystemColorsEnabled()为您的iPhone 6或iPhone 6 plus返回true,因此它看起来更暗。
To disable it, go to Settings -> General -> Accessibility -> Increase Contrast -> Darken Colours, toggle it off should work.
要禁用它,请转到设置 - >常规 - >辅助功能 - >增加对比度 - >使颜色变暗,如果工作则将其关闭。
Edit
编辑
As stated in the document UIVibrancyEffect.
如文件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.
活力效果取决于颜色。您添加到contentView的任何子视图都必须实现tintColorDidChange方法并相应地更新自己。具有UIImageRenderingModeAlwaysTemplate渲染模式的图像的UIImageView对象以及UILabel对象将自动更新。
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.
我们应该使用UIImageRenderingModeAlwaysTemplate渲染模式的图像来自动更新UIImageView对象。应用此功能可使UIVibrancyEffect在iPhone设备上充满活力。
#2
0
I am not sure but I Used var
instead of let
in below lines and it was working for me.
我不确定,但我使用var而不是让它在下面的行中,它对我有用。
var vibrancyEffect = UIVibrancyEffect(forBlurEffect: blurEffect)
May be this will help you.
可能这会对你有所帮助。
I was using like this.
我是这样用的。
var vibrancyEffect = UIVibrancyEffect(forBlurEffect: blurEffect)
var vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect)
vibrancyEffectView.frame = view.bounds
#3
0
Use generic RGB, not sRGB or device RGB.
使用通用RGB,而不是sRGB或设备RGB。
#1
3
It is perhaps that UIAccessibilityDarkerSystemColorsEnabled()
returns true for your iPhone 6 or iPhone 6 plus, so it appears darker.
或许UIAccessibilityDarkerSystemColorsEnabled()为您的iPhone 6或iPhone 6 plus返回true,因此它看起来更暗。
To disable it, go to Settings -> General -> Accessibility -> Increase Contrast -> Darken Colours, toggle it off should work.
要禁用它,请转到设置 - >常规 - >辅助功能 - >增加对比度 - >使颜色变暗,如果工作则将其关闭。
Edit
编辑
As stated in the document UIVibrancyEffect.
如文件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.
活力效果取决于颜色。您添加到contentView的任何子视图都必须实现tintColorDidChange方法并相应地更新自己。具有UIImageRenderingModeAlwaysTemplate渲染模式的图像的UIImageView对象以及UILabel对象将自动更新。
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.
我们应该使用UIImageRenderingModeAlwaysTemplate渲染模式的图像来自动更新UIImageView对象。应用此功能可使UIVibrancyEffect在iPhone设备上充满活力。
#2
0
I am not sure but I Used var
instead of let
in below lines and it was working for me.
我不确定,但我使用var而不是让它在下面的行中,它对我有用。
var vibrancyEffect = UIVibrancyEffect(forBlurEffect: blurEffect)
May be this will help you.
可能这会对你有所帮助。
I was using like this.
我是这样用的。
var vibrancyEffect = UIVibrancyEffect(forBlurEffect: blurEffect)
var vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect)
vibrancyEffectView.frame = view.bounds
#3
0
Use generic RGB, not sRGB or device RGB.
使用通用RGB,而不是sRGB或设备RGB。