ios - 使用 GPUImage 的模糊 View 动画

标签 ios animation blur gpuimage

我目前尝试在 View 上添加模糊动画以进行过渡。 我正在使用实现 GPUImageGaussianBlurFilterGPUImage 框架。

它可以工作,但应用于滤镜的效果不够强。我尝试使用 filter.blurRadiusInPixels 值,但它似乎不会改变我尝试输入的任何值。

这是我的代码:

//First I init a ImageView which have the size of the frame of my view

     UIImageView * blurredArea = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

//hide this imageView for the moment

            blurredArea.alpha = 0;

 //In this part I take a snapshot of my current view that I keep in snapshot           


UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
                [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
                UIImage * snapshot=UIGraphicsGetImageFromCurrentImageContext();
                UIGraphicsEndImageContext();

//Finally I init my GaussianFilter on my snapshot

            GPUImageGaussianBlurFilter * filter = [[GPUImageGaussianBlurFilter alloc] init];
            UIImage * blurred = [filter imageByFilteringImage: snapshot];

            blurredArea.image = blurred;

//Here I define the strength of the blur effect but it seems to do nothing whatever the value is putted.

            filter.blurRadiusInPixels = 1;

            [self.view addSubview:blurredArea];

            [UIView animateWithDuration:0.8f animations:^{

//Animate the blurred imageview alpha but not enough blurred.

                blurredArea.alpha = 1;
            }

enter image description here

最佳答案

如果你只想在通知中心做一些看起来像 iOS 模糊的模糊(我建议你这样做),从 iOS8 开始,UIView 有一个很棒的扩展,叫做 UIVisualEffectView。

有一些链接可以让您逐步实现该杰作:

当然,这仅适用于 iOS8,因此它可能不适合您,但我将其放在将搜索类似解决方案的其他人身上。

关于ios - 使用 GPUImage 的模糊 View 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31606012/

相关文章:

ios - Phonegap (Cordova) mailto 与 CC 的链接不起作用

android - 开启硬件加速时的模糊效果

jQuery 模糊有一个异常(exception)

java - Sprite 动画计时java swing

css - 保持动画 flex 盒的行高

c++ - QGraphicsBlurEffect 调整 Text 的大小但不调整 Widget 本身

iOS 图片编辑开源库——或者只是一些小技巧

ios - Instruments Leaks 显示不存在的方法调用

ios - UILabel 中的换行符在构建时被忽略

javascript - 通过使用带有 Javascript 的 addClass/removeClass 单击按钮在 div 上触发动画