objective c - How To Add Visual Effect Views Blur On All Views Storyboard iOS? -


i need add visual effect view center activityindicator loading label device fullscreen using objective c. using storyboard below posted image cant add visual effect blur view on over top side.

enter image description here

you can try below code add blur effects:

// usage [loginview blurbackgroundwithscreenshotview:backgroundimageview                                    withtype:blursubview                                   withcolor:blurblackview                                   withpoint:cgpointzero];  // //  uiimage+blur.h // //  created ankit thakur on 07/03/14. // #import <uikit/uikit.h>  @interface uiimage (blur) - (uiimage*) blurredsnapshot; @end  // //  uiimage+blur.m // //  created ankit thakur on 07/03/14. //  #import "uiimage+blur.h" #import <accelerate/accelerate.h> @implementation uiimage (blur)  - (uiimage *)applyblurwithradius:(cgfloat)blurradius tintcolor:(uicolor *)tintcolor saturationdeltafactor:(cgfloat)saturationdeltafactor maskimage:(uiimage *)maskimage {     // check pre-conditions.     if (self.size.width < 1 || self.size.height < 1) {         nslog (@"*** error: invalid size: (%.2f x %.2f). both dimensions must >= 1: %@", self.size.width, self.size.height, self);         return nil;     }     if (!self.cgimage) {         nslog (@"*** error: image must backed cgimage: %@", self);         return nil;     }     if (maskimage && !maskimage.cgimage) {         nslog (@"*** error: maskimage must backed cgimage: %@", maskimage);         return nil;     }      cgrect imagerect = { cgpointzero, self.size };     uiimage *effectimage = self;      bool hasblur = blurradius > __flt_epsilon__;     bool hassaturationchange = fabs(saturationdeltafactor - 1.) > __flt_epsilon__;     if (hasblur || hassaturationchange) {         uigraphicsbeginimagecontextwithoptions(self.size, no, [[uiscreen mainscreen] scale]);         cgcontextref effectincontext = uigraphicsgetcurrentcontext();         cgcontextscalectm(effectincontext, 1.0, -1.0);         cgcontexttranslatectm(effectincontext, 0, -self.size.height);         cgcontextdrawimage(effectincontext, imagerect, self.cgimage);          vimage_buffer effectinbuffer;         effectinbuffer.data     = cgbitmapcontextgetdata(effectincontext);         effectinbuffer.width    = cgbitmapcontextgetwidth(effectincontext);         effectinbuffer.height   = cgbitmapcontextgetheight(effectincontext);         effectinbuffer.rowbytes = cgbitmapcontextgetbytesperrow(effectincontext);          uigraphicsbeginimagecontextwithoptions(self.size, no, [[uiscreen mainscreen] scale]);         cgcontextref effectoutcontext = uigraphicsgetcurrentcontext();         vimage_buffer effectoutbuffer;         effectoutbuffer.data     = cgbitmapcontextgetdata(effectoutcontext);         effectoutbuffer.width    = cgbitmapcontextgetwidth(effectoutcontext);         effectoutbuffer.height   = cgbitmapcontextgetheight(effectoutcontext);         effectoutbuffer.rowbytes = cgbitmapcontextgetbytesperrow(effectoutcontext);          if (hasblur) {             // description of how compute box kernel width gaussian             // radius (aka standard deviation) appears in svg spec:             // http://www.w3.org/tr/svg/filters.html#fegaussianblurelement             //             // larger values of 's' (s >= 2.0), approximation can used: 3             // successive box-blurs build piece-wise quadratic convolution kernel,             // approximates gaussian kernel within 3%.             //             // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)             //             // ... if d odd, use 3 box-blurs of size 'd', centered on output pixel.             //             cgfloat inputradius = blurradius * [[uiscreen mainscreen] scale];             nsuinteger radius = floor(inputradius * 3. * sqrt(2 * m_pi) / 4 + 0.5);             if (radius % 2 != 1) {                 radius += 1; // force radius odd 3 box-blur methodology works.             }             vimageboxconvolve_argb8888(&effectinbuffer, &effectoutbuffer, null, 0, 0, radius, radius, 0, kvimageedgeextend);             vimageboxconvolve_argb8888(&effectoutbuffer, &effectinbuffer, null, 0, 0, radius, radius, 0, kvimageedgeextend);             vimageboxconvolve_argb8888(&effectinbuffer, &effectoutbuffer, null, 0, 0, radius, radius, 0, kvimageedgeextend);         }         bool effectimagebuffersareswapped = no;         if (hassaturationchange) {             cgfloat s = saturationdeltafactor;             cgfloat floatingpointsaturationmatrix[] = {                 0.0722 + 0.9278 * s,  0.0722 - 0.0722 * s,  0.0722 - 0.0722 * s,  0,                 0.7152 - 0.7152 * s,  0.7152 + 0.2848 * s,  0.7152 - 0.7152 * s,  0,                 0.2126 - 0.2126 * s,  0.2126 - 0.2126 * s,  0.2126 + 0.7873 * s,  0,                 0,                    0,                    0,  1,             };             const int32_t divisor = 256;             nsuinteger matrixsize = sizeof(floatingpointsaturationmatrix)/sizeof(floatingpointsaturationmatrix[0]);             int16_t saturationmatrix[matrixsize];             (nsuinteger = 0; < matrixsize; ++i) {                 saturationmatrix[i] = (int16_t)roundf(floatingpointsaturationmatrix[i] * divisor);             }             if (hasblur) {                 vimagematrixmultiply_argb8888(&effectoutbuffer, &effectinbuffer, saturationmatrix, divisor, null, null, kvimagenoflags);                 effectimagebuffersareswapped = yes;             }             else {                 vimagematrixmultiply_argb8888(&effectinbuffer, &effectoutbuffer, saturationmatrix, divisor, null, null, kvimagenoflags);             }         }         if (!effectimagebuffersareswapped)             effectimage = uigraphicsgetimagefromcurrentimagecontext();         uigraphicsendimagecontext();          if (effectimagebuffersareswapped)             effectimage = uigraphicsgetimagefromcurrentimagecontext();         uigraphicsendimagecontext();     }      // set output context.     uigraphicsbeginimagecontextwithoptions(self.size, no, [[uiscreen mainscreen] scale]);     cgcontextref outputcontext = uigraphicsgetcurrentcontext();     cgcontextscalectm(outputcontext, 1.0, -1.0);     cgcontexttranslatectm(outputcontext, 0, -self.size.height);      // draw base image.     cgcontextdrawimage(outputcontext, imagerect, self.cgimage);      // draw effect image.     if (hasblur) {         cgcontextsavegstate(outputcontext);         if (maskimage) {             cgcontextcliptomask(outputcontext, imagerect, maskimage.cgimage);         }         cgcontextdrawimage(outputcontext, imagerect, effectimage.cgimage);         cgcontextrestoregstate(outputcontext);     }      // add in color tint.     if (tintcolor) {         cgcontextsavegstate(outputcontext);         cgcontextsetfillcolorwithcolor(outputcontext, tintcolor.cgcolor);         cgcontextfillrect(outputcontext, imagerect);         cgcontextrestoregstate(outputcontext);     }      // output image ready.     uiimage *outputimage = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();      return outputimage; }  - (uiimage*) blurredsnapshot{      uicolor *tintcolor = [uicolor colorwithwhite:0.8 alpha:0.7];     //     uicolor *tintcolor = [uicolor colorwithred:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.5];     uiimage *image = [self applyblurwithradius:5 tintcolor:tintcolor saturationdeltafactor:1.8 maskimage:nil];     return image; } @end  // //  blurview.h // //  created ankit thakur on 07/03/14. // #import <uikit/uikit.h>  typedef ns_enum(nsuinteger, blurviewtype) {     blursubview,     blurpopview }; typedef ns_enum(nsuinteger, blurviewcolortype) {     blurwhiteview,     blurblackview };  @interface blurview : uiview  - (void) blurbackgroundwithscreenshotview:(uiview*)screenshotview withtype:(blurviewtype)type withcolor:(blurviewcolortype)colortype withpoint:(cgpoint)point;   @end   // //  blurview.m // //  created ankit thakur on 07/03/14. //  #import "blurview.h" #import "uiimage+blur.h"  @interface blurview (){ }  @end  @implementation blurview  - (id)initwithcoder:(nscoder *)adecoder {     self = [super initwithcoder:adecoder];     if (self) {         // initialization code     }     return self; }  - (void) blurbackgroundwithscreenshotview:(uiview*)screenshotview withtype:(blurviewtype)type withcolor:(blurviewcolortype)colortype withpoint:(cgpoint)point{      nslog(@"%ld",(long)screenshotview.tag);      if ([self viewwithtag:111]) {         [[self viewwithtag:111] removefromsuperview];     }     @autoreleasepool {          uigraphicsbeginimagecontext(screenshotview.frame.size);         if([self respondstoselector:@selector(drawviewhierarchyinrect:afterscreenupdates:)]){             [screenshotview drawviewhierarchyinrect:self.frame afterscreenupdates:no];         }         else{             [screenshotview.layer renderincontext:uigraphicsgetcurrentcontext()];         }         uigraphicsendimagecontext();          cgpoint origin = self.frame.origin;         switch (type) {             case blursubview:                 origin.x = - origin.x;                 origin.y = -origin.y;                 break;              case blurpopview:                 origin.x = -point.x;                 origin.y = -point.y;                 break;              default:                 break;         }          uiimage *blurimage =  nil;         uigraphicsbeginimagecontext(self.bounds.size);         cgcontexttranslatectm(uigraphicsgetcurrentcontext(), origin.x, origin.y);         [screenshotview.layer renderincontext:uigraphicsgetcurrentcontext()];         blurimage = uigraphicsgetimagefromcurrentimagecontext();         uigraphicsendimagecontext();          nsdata *imagedata = uiimagejpegrepresentation(blurimage, 1.0);         blurimage = [uiimage imagewithdata:imagedata];         switch (colortype) {             case blurwhiteview:                 blurimage = [blurimage blurredwhitesnapshot];                 break;             case blurblackview:                 blurimage = [blurimage blurredblacksnapshot];                 break;             default:                 break;         }          uiimageview *imageview = [[uiimageview alloc] initwithframe:self.bounds];         imageview.tag = 111;         imageview.image = blurimage;         [self addsubview:imageview];         [self sendsubviewtoback:imageview];          blurimage = nil;      } } @end 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -