ios - UIImage+ImageEffects doesn't work on device -
i have modal view want present results of calculation. in order make ios7 look, want tinted background popup view blured background.
i managed got thing work using files "uiimage+imageeffects .h/m" apple.
this viewdidload of modal view:
- (void)viewdidload { [super viewdidload]; /* how works self.image screenshot of vc presenting modal view 1- set background screenshot of previous viewcontroler 2- hide popup view 3- set background of popup blured snapshot of container view (self.view) 4- unhide popup view , set radius 5- create tinted version of background image (what got previous view controller 6- set background of self.view tinted version */ // *** 1 *** self.view.backgroundcolor=[uicolor colorwithpatternimage:self.image]; // *** 2 *** self.containerview.hidden=yes; // *** 3 *** uiimage *pepe=[self bluredimagefromview:self.containerview withbackground:self.view withbackgroundtintcolor:[uicolor colorwithwhite:1 alpha:0.75]]; self.containerview.backgroundcolor=[uicolor colorwithpatternimage:pepe]; // *** 4 *** self.containerview.hidden=no; self.containerview.layer.cornerradius=4.5f; // *** 5 *** uiimage *tintedbackground =[self.image applyblurwithradius:0 tintcolor:[uicolor colorwithred:0.85 green:0.85 blue:0.85 alpha:0.35] saturationdeltafactor:1.8 maskimage:nil]; // *** 6 *** self.view.backgroundcolor=[uicolor colorwithpatternimage:tintedbackground]; }
it works on simulators when tried onmy iphone (4s), when modal view presented, i've got black screen. no errors, no complaining console, no nothing.
any thoughts?
edit
i add code:
if (!self.image) nslog (@"self.image empty");
at beginning of viewdidload
it seems on simulator self.image not nil whereas on device is. i've tried instantiate self.image prepareforsegue on parent vc doesn't work.
i don't know how bluredimagefromview
working, there security(sandbox) differences between simulator , actual ios device (particularly resizablesnapshotviewfromrect:
, drawviewhierarchyinrect:
) might explain why works (but doesn't on device.)
check out thread @ raywenderlich.com got advice apple developer tech support. example code apparently apple.
- (ibaction)doblurandcrop:(id)sender { uiimage *snapshotimage; /* draw image of views below our view */ uigraphicsbeginimagecontextwithoptions(self.sourceimageview.bounds.size, no, 0); bool successfuldrawhierarchy = [self.sourceimageview drawviewhierarchyinrect:self.sourceimageview.bounds afterscreenupdates:yes]; if ( successfuldrawhierarchy ) { snapshotimage = uigraphicsgetimagefromcurrentimagecontext(); } else { nslog(@"drawviewhierarchyinrect:afterscreenupdates: failed - there's nothing draw..."); } uigraphicsendimagecontext(); if ( successfuldrawhierarchy ) { /* calculate coordinates of rectangle we're interested in within returned image */ cgrect croprect = cgrectoffset(self.targetimageview.frame, - self.sourceimageview.frame.origin.x, - self.sourceimageview.frame.origin.y); /* draw cropped section clipping region */ uigraphicsbeginimagecontextwithoptions(croprect.size, yes, 0); cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextcliptorect(context, cgrectmake(0, 0, croprect.size.width, croprect.size.height)); cgrect targetrectangeforcrop = cgrectmake(-croprect.origin.x, -croprect.origin.y, snapshotimage.size.width, snapshotimage.size.height); [snapshotimage drawinrect:targetrectangeforcrop]; uiimage *croppedsnapshotimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); /* apply special effect resulting image , copy place on screen */ uicolor *tintcolor = [uicolor colorwithwhite:1.0 alpha:0.3]; self.targetimageview.image = [croppedsnapshotimage applyblurwithradius:5 tintcolor:tintcolor saturationdeltafactor:1.8 maskimage:nil]; } }
Comments
Post a Comment