objective c - How can I achieve luminescent shadows? -
- the entire mockup has shadow reminds me of philip's ambilight tvs.
- look @ "trailer , photos" section tiles have type of shadow.
this effect fascinating watch , i'd incorporate app.
here's i've thought:
- take screenshot of view , enlarge 110%
- place behind view.
- blur screenshot.
- apply inner white shadow.
any suggestions?
your thoughts correct, there no need apply inner shadow, it's possible add transparent insets screenshot, , when blurred, create gradient you're looking for.
the following code should job:
- (void)addluminescentshadowtoview:(uiview*)contentview { //the bigger radius of blur //the more spread shadow cgfloat blurradius = 15.0f; //in order shadow becomes transparent on edeges //we're adding transparent insets snapshot cgfloat insetssize = 2.0f * blurradius; //getting superview of content view //it's important before getting snapshot //as during snapshot parent of content view //might temporary changed //superview used later insert shadow uiview* contentviewsuperview = contentview.superview; //code following methods sourced //http://code.tutsplus.com/tutorials/adding-blur-effects-on-ios--cms-21488 , modified //taking snapshot of content view //method modified add transparent insets snapshot uiimage* snapshot = [self takesnapshotofview: contentview withtransparentinsets: insetssize]; //applying blur snapshot uiimage* blurredsnapshot = [self blurwithcoreimage: snapshot withradius: blurradius]; //creating view displays shadow uiimageview* shadowview = [[uiimageview alloc] initwithimage: blurredsnapshot]; shadowview.center = contentview.center; //you control appearence of effect modifying scale , alpha //scale not uniform prevent spreading of shadow height, shown on example shadowview.transform = cgaffinetransformmakescale(1.05f, 0.95f); shadowview.alpha = 1.0f; //inserting shadow below content [contentviewsuperview insertsubview:shadowview belowsubview:contentview]; } - (uiimage *)takesnapshotofview:(uiview *)view withtransparentinsets:(cgfloat)insets { //creating bitmap context cgrect contextrect; contextrect.origin = cgpointzero; contextrect.size = cgsizemake(view.frame.size.width + 2.0f * insets, view.frame.size.height + 2.0f * insets); uigraphicsbeginimagecontext(contextrect.size); cgcontextclearrect(uigraphicsgetcurrentcontext(), contextrect); //rendering views hierarchy context [view drawviewhierarchyinrect:cgrectmake(insets, insets, view.frame.size.width, view.frame.size.height) afterscreenupdates:yes]; //getting result image uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return image; } - (uiimage *)blurwithcoreimage:(uiimage *)sourceimage withradius:(cgfloat)radius { ciimage *inputimage = [ciimage imagewithcgimage:sourceimage.cgimage]; //apply gaussian blur filter cifilter *gaussianblurfilter = [cifilter filterwithname: @"cigaussianblur"]; [gaussianblurfilter setvalue: inputimage forkey:@"inputimage"]; [gaussianblurfilter setvalue: @(radius) forkey:@"inputradius"]; cicontext *context = [cicontext contextwithoptions:nil]; //creating output uiimage cgimageref cgimage = [context createcgimage:gaussianblurfilter.outputimage fromrect:[inputimage extent]]; uiimage* outputimage = [uiimage imagewithcgimage:cgimage scale:1.0f orientation:uiimageorientationup]; cfrelease(cgimage); return outputimage; }
Comments
Post a Comment