UIBlurEffect 始终为零

UIBlurEffect is always nil

我一直在尝试为我的应用程序添加模糊效果,并且在使用断点对其进行调试时,UIBlurEffect 变量始终为零。

以下是我使用的代码:

UIBlurEffect *effect = [[UIBlurEffect alloc] init];
effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *bluredView = [[UIVisualEffectView alloc] initWithEffect: effect];
bluredView.frame = self.view.bounds;
[self.view addSubview:bluredView];

我尝试了一些不同的东西,例如,直接使用它而不是 alloc 和 init UIBlurEffect,如下所示:

UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];

它仍然总是设置为零。 我缺少进口商品吗?我在我的 .h 文件中导入了 UIKit,但由于某些原因 'effect' 始终为 nil。

如果有人有同样的经历,如果你能分享你的经验,我将不胜感激。

对此事的任何帮助都会很棒! 提前致谢!

你 运行 在 iOS 7 吗? UIBlurEffect 仅适用于 iOS 8 及更高版本。

这两个 Git 可能会对你有所帮助,即使我第一次没有看到他们使用 UIBlurImage。试试看:)

LBBlurredImage

BTGlassScrollView