gpt4 book ai didi

ios - 带有 UIVisualEffectView 的奇怪模糊伪像

转载 作者:行者123 更新时间:2023-11-29 10:34:54 24 4
gpt4 key购买 nike

我有一个 UIVisualEffectView,它在出现时会导致一些奇怪的人工制品。 UIVisualEffectView 在 View 加载后添加到代码中,因为它在 iOS 7 中不可用。

看看街景图像上模糊的文字背景:http://s.swic.name/Z3UL

模糊需要 0.1 秒才能出现,在此之前它只是一个较低分辨率的背景,就像尚未计算模糊一样。

知道发生了什么事吗?我正在使用这段代码在 awakeFromNib 中添加模糊

- (void)addBlurWithColor:(UIColor *)color andStyle:(UIBlurEffectStyle)style andVibrancy:(BOOL)vibrancy
{
if (UIDevice.supportsVisualEffects && NSClassFromString(@"UIVisualEffectView") && !UIAccessibilityIsReduceTransparencyEnabled()) {
self.backgroundColor = color;

UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:style];
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = self.bounds;
visualEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

NSArray *subviews = self.subviews;

[self addSubview:visualEffectView];
[self sendSubviewToBack:visualEffectView];

if (vibrancy) {
UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect];
UIVisualEffectView *vibrancyEffectView = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect];
[vibrancyEffectView setFrame:self.bounds];
vibrancyEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

for (UIView *subview in subviews) {
[vibrancyEffectView.contentView addSubview:subview];
}

[[visualEffectView contentView] addSubview:vibrancyEffectView];
}
}
}

编辑:视频只是启用了慢速动画,过渡是常规的推送转场。

Edit2:如果我只是在 Interface Builder 中拖放一个“带有模糊的 UIVisualEffectView”,我会得到同样的奇怪行为,所以上面的代码不应该受到指责。

最佳答案

发现问题,当 View 出现时,我正在 [UIView transitionWithView:...] 中重新加载 tableview,这改变了 alpha,这显然是一个很大的禁忌,当涉及到 UIVisualEffectViews!

根据 UIVisualEffectView 文档;

When using the UIVisualEffectView class, avoid alpha values that are less than 1. Creating views that are partially transparent causes the system to combine the view and all the associated subviews during an offscreen render pass. UIVisualEffectView objects need to be combined as part of the content they are layered on top of in order to look correct. Setting the alpha to less than 1 on the visual effect view or any of its superviews causes many effects to look incorrect or not show up at all.

https://developer.apple.com/library/ios/documentation/uikit/reference/UIVisualEffectView/index.html

关于ios - 带有 UIVisualEffectView 的奇怪模糊伪像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27606107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com