ios - how to use drawViewHierarchyInRect -


i want create snapshot image uiview, used use renderinrect, slow, , found drawviewhierarchyinrect newer api since ios 7, want try it.

i write below code, never create valid image, blank image.

-(void)drawrect:(cgrect)rect {     uigraphicsbeginimagecontextwithoptions(_mapview.bounds.size, _mapview.opaque, [[uiscreen mainscreen] scale]);     cgcontextref context = uigraphicsgetcurrentcontext();      // used use renderincontext, it's slow     // [mapview.layer renderincontext:context];      [_mapview drawviewhierarchyinrect:_mapview.bounds afterscreenupdates:yes];     uiimage *image = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();     self.thumbimageview = [[uiimageview alloc] initwithimage:image];     [self addsubview:self.thumbimageview]; } 

the -drawviewhierarchyinrect:afterscreenupdates:, lets render snapshot of complete view hierarchy visible onscreen bitmap context.

renderincontext: renders directly calayer's render tree valid core graphics context.

if want render view uiimage rather having on view hierarchy, should using renderincontext.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -