Using the blur effect in IOS 8

Source: Internet
Author: User

In IOS 7 comes a blurred background effect, and Apple's official sample code provides an effect on how to use Vimage, Quartz. Then, after IOS 8 comes out, it provides a UIVisualEffectView objects that can be stacked on the inheriting class, which, in addition to being commonly used to UIView UIView UIImageView add blur, can be more easily achieved.

Bluring Images on IOS 7

Apple provides a sample code that can be used: blurring and tinting an Image. Implementation in UIImageEffects/UIImageEffects.m this file, from his header file, you can see how you can use these effects.

Actually, it's a detail.

As can be seen from sample code, the actual use of three times box blur to approach the effect of Gaussian blur, the speed is also faster. The related principle can see this link: Filter primitive ' Fegaussianblur '

How to use

I have extracted these two actual files into a pod that can be executed after the Podfile is added to the formula pod install :

pod ‘UIImageBlurEffectCategory‘, :git => ‘https://github.com/vc7/UIImageBlurEffectCategory.git‘

Then introduce the header file:

#import <UIImageBlurEffectCategory/UIImageBlurEffectCategory.h>

I changed code UIImage to use category to provide a way to use the class methods. For example, if you want to produce a simple blurred image, you can do it in the following ways:

UIImage *bluredImage = [UIImage imageByApplyingLightEffectToImage:[UIImage imageNamed:@"myImage.jpg"]];

The previously provided sample code provides a larger variation of the space, there are more parameters (blur radius, tint color, saturation delta factor and mask image) can adjust the blur effect, to IOS 8 or is available.

IOS 8, Uivisualeffectview

In the past, if you want to blur a view, you need to draw a snapshot of that view, then apply the blur to him and add it to a uiimageview.

After IOS 8, UIKit provides a simple way to blur the effect, and a few steps can directly blur the UIView instances.

Easy process

Objective-c
Uivisualeffect*Blureffect =[UiblureffectEffectwithstyle:Uiblureffectstylelight];uivisualeffectview  *visualeffectview = [[< span class= "n" >uivisualeffectview alloc initwitheffect :blureffect]; visualeffectview. Frame = imageview. Bounds[imageview  Addsubview:visualeffectview];        
Swift
var visualeffectview = uivisualeffectview< Span class= "P" > (effect: uiblureffect ( style: . Lightas uivisualeffectview visualeffectview. Frame = imageview. Boundsimageview. Addsubview (visualeffectview)      
The uiblureffect of the human species

There are several kinds of uiblureffect that can be used:

    • uiblureffectstyleextralight – Blur adds a brighter hue (hue) adjustment effect than blurring the image
    • uiblureffectstylelight – Add and blur the same hue adjustment effect after Blur
    • Uiblureffectstyledark – Blur add a darker hue effect compared to blurred image

The following is a split effect display with the foreground plus the original picture:

Theory

The original code that used the vimage was easier to make than to make a guest of the effect. The new visual effect that IOS 8 provides is the easiest way to get there and see what you need.

And in order to understand sample code also a little bit of information, and some of the previously not touched by the calculation formula, it takes some time to digest these things. It takes a little time to understand what he did behind his back, and he was filled with harvesting.

Using the blur effect in IOS 8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.