iphone - iOS the lower performance of CGContext when draw a lot of gradient rectange -


the effect want implement:

here code snippet:

    (nsinteger = 0; < count; i++) {     key = [nsstring stringwithformat:@"property%d", i];     barheigth = valueheight * ([[_values objectatindex:i] floatvalue]/valuemax);     cgrect barrect = cgrectmake(marginx, marginy - barheigth, barwidth, barheigth);     cgrect bgbarrect = cgrectmake(marginx, 0, barwidth, marginy);     barproperty *property = _barviewdic[key];     if (!property) {         property = [[barproperty alloc] init];         property.gradientstartcolor = rgbacolor(93, 193, 247, 0.9);         property.gradientendcolor = rgbacolor(37, 114, 207, 0.9);         _barviewdic[key] = property;         [property release];     }     property.foreheadrect = barrect;     property.backgroundrect = bgbarrect;     [_barpropertiesarray addobject:property];      key = [nsstring stringwithformat:@"barview%d", i];     barview *barview = _barviewdic[key];     if (!barview) {         barview = [[barview alloc] initwithframe:barrect];         barview.backgroundcolor = [uicolor clearcolor];         _barviewdic[key] = barview;         [barview release];     }     barview.property = property;     barview.frame = bgbarrect;     [self addsubview:barview];     marginx += barwidth + padding; } 

on screentshot, every blue gradient rectangle instance of barview problem here: barview.frame = bgbarrect draw function slow,
otherwisebarview.frame = barrect,
goes , performance good.

note:the different between bgbarrect , barrect height, height of bgbarrect greater height of barrect

here draw code of barview:

- (cgrect)getbarbounds {     cgfloat marginy = cgrectgetheight(self.bounds) - cgrectgetheight(self.property.foreheadrect);     return cgrectmake(0, marginy, cgrectgetwidth(self.property.foreheadrect), cgrectgetheight(self.property.foreheadrect)); } // override drawrect: if perform custom drawing. // empty implementation adversely affects performance during animation. - (void)drawrect:(cgrect)rect {     cgrect barbounds = [self getbarbounds];     cgpoint startpoint = cgpointmake(cgrectgetmidx(barbounds)/2, 0);     cgpoint endpoint = cgpointmake(cgrectgetmidx(barbounds)/2, cgrectgetmaxy(barbounds));      cgcolorspaceref patternsapce = cgcolorspacecreatepattern(null);      static const cgpatterncallbacks callbacks = {0, &drawpattern, null};     cgpatternref pattern = cgpatterncreate(null, barbounds,                                             cgaffinetransformidentity,                                             h_pattern_size,                                             v_pattern_size,                                             kcgpatterntilingnodistortion,                                             true,                                             &callbacks);      cgcontextref context = uigraphicsgetcurrentcontext();      cgcontextsavegstate(context);     cgcontextcliptorect(context, barbounds);     // drawing code     cgfloat alpha = 1.0;     cgcontextsetfillcolorspace(context, patternsapce);      cgcontextsetfillpattern(context, pattern, &alpha);     cgcontextfillrect(context, barbounds);      cggradientref mygradient;     cgcolorspaceref mycolorspace;     const size_t num_locations = 2;     cgfloat locations[2] = { 0.0, 1.0 };     cgfloat components[8] = {         93/255.0, 193/255.0, 247/255.0, 0.9,         37/255.0, 114/255.0, 207/255.0, 0.9     };      mycolorspace = cgcolorspacecreatedevicergb();     mygradient = cggradientcreatewithcolorcomponents (mycolorspace, components,                                                       locations, num_locations);      cgcontextdrawlineargradient(context, mygradient, startpoint, endpoint, 0);      cgcolorspacerelease(patternsapce);     cgpatternrelease(pattern);      cgcontextrestoregstate(context);         } 

anybody knows point, in advance.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -