本文介绍了磨砂玻璃(iOS 7 模糊)效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 UIImageView 中应用磨砂玻璃效果.

我尝试实施我发现的

更新 1

所以经过一些研究,我最终发现与 OS X 版本的库相比,iOS 的 Core Image 仍然不完整.所以我在谷歌上搜索了很多,我找到了两个解决方案,一个更简单,另一个更广泛和复杂.

所以,例如,在几行中我可以得到我想要的结果(其中 originalImage 是应用效果的 UIImage):

GPUImageGaussianBlurFilter *blurFilter = [[GPUImageGaussianBlurFilter alloc] init];模糊过滤器.blurSize = 2;UIImage *blurImage = [blurFilter imageByFilteringImage:resizedImage];

更新 2

在 Apple 发布 iOS 7 后,一些开发者找到了一种变通方法,可以像 Apple 在默认 iOS 应用中所做的一样,因为 Apple 没有为此提供 API.在我看来,最简单、更好的解决方案就是这个.为什么我认为它是最好的?因为即使它背后的一些视图移动,模糊仍然可以很好地使用更新的效果,正如我们所期望的那样. 但是,请记住,它依赖于 iOS 7 SDK 才能工作,并且它如果 Apple 更改 UIToolbar,可能会有风险.

更新 3

Apple 提到,在 WWDC 2013(Session 226 - 在 iOS 上实现引人入胜的 UI)他们将在 UIImage 上提供一个类别类,称为 UIImage+ImageEffects(我用谷歌搜索了它,并在这里找到,但它可以在 开发者门户 - 在搜索框中搜索 UIImageEffects).使用此类别,您可以使用多种方法(浅色、深色、特定颜色等)在静态 UIImage 中应用模糊.另外,昨天我看到了这个组件,发现它很有趣,因为你可以应用效果(基于上述类别)在一个框架中.

更新 4

最后,在 iOS 8 上,Apple 发布了可以轻松进行实时模糊的新类.使用 UIVisualEffectUIVisualEffectView,您可以快速为您的应用添加实时模糊.这是 Ryan Nystrom 关于如何使用这些类(和一般模糊):

I am trying to apply a frosted glass effect in a UIImageView.

I tried to implement what I've found in this question, but the result wasn't acceptable.I wanted something like this:

Also, we can see that iOS 7 uses this kind of effect in a lot of places. How can we reproduce it?

解决方案

A good tutorial about CoreImage is here, showing how to apply filters and more:

http://www.raywenderlich.com/5689/beginning-core-image-in-ios-5

UPDATE 1

So after a little bit of research, I ended up discovering that the Core Image for the iOS is still incomplete, when comparing to the OS X version of the library. So I googled a lot, and I find two solutions, one of them more simple, and the other much wider and complex library.

So, for example, in a few lines I can get the result I want (where originalImage is the UIImage to apply the effect):

GPUImageGaussianBlurFilter *blurFilter = [[GPUImageGaussianBlurFilter alloc] init];
blurFilter.blurSize = 2;
UIImage *blurImage = [blurFilter imageByFilteringImage:resizedImage];

UPDATE 2

After Apple announced iOS 7, some developers found a workaround to do the same that Apple did in the default iOS apps, as Apple didn't provide an API for that. The simplest and better solution, in my opinion, is this one. Why I think it's the best? Because even if some view behind it moves, the blur still works great with the updated effect, as we expect it should work. However, bear in mind that it depends on the iOS 7 SDK in order to work, and it can be risky if Apple changes UIToolbar.

UPDATE 3

Apple mentioned, at WWDC 2013 (Session 226 - Implementing Engaging UI on iOS) they would provide a category class on UIImage, called UIImage+ImageEffects (I googled it, and found here, but it's available in Developer Portal - search for UIImageEffects in the search box). With this category, you can apply the blur in a static UIImage, using several methods (light, dark, with a specific color, etc.). Also, yesterday I saw this component and found it pretty interesting, as you can apply the effect (based on the above mentioned category) in a frame.

UPDATE 4

Finally, on iOS 8, Apple released new classes that can do live blur easily. With UIVisualEffect and UIVisualEffectView, you can quickly add live blur to your apps. Here is a good tutorial from Ryan Nystrom on how to use those classes (and in blur in general):

这篇关于磨砂玻璃(iOS 7 模糊)效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 08:23