ios - Smooth scaling of vector graphics in UIView -


so have subclassed uiview , added drawing code. scaling resulting view , down. view resolution independent legible @ size, , won't need manage multiple images etc. etc.

as test made bit of drawing code looks this. creates concentric ovals fit within whatever frame size uiview has. outside ring little smaller frame isn't clipped. fine this. actual graphic more complex , contain text must readable @ small sizes , things of nature.

- (void)drawrect:(cgrect)rect {     uicolor* color = [uicolor colorwithred: 0.833 green: 0.833 blue: 0.833 alpha: 1];      float width = self.bounds.size.width;     float height = self.bounds.size.height;     float scalepercent = 0.8;      for(int = 0; < 10; i++){          width  = width * scalepercent;         height = height * scalepercent;          float x = (self.bounds.size.width - width) / 2;         float y = (self.bounds.size.height - height) / 2;          uibezierpath* ovalpath = [uibezierpath bezierpathwithovalinrect: cgrectmake(x, y, width, height)];         [color setstroke];         ovalpath.linewidth = 2;         [ovalpath stroke];     } } 

now here's scaling:

- (void) makebig{      [uiview animatewithduration:0.5                           delay:0                         options:uiviewanimationoptionbeginfromcurrentstate                      animations:(void (^)(void)) ^{                          self.transform = cgaffinetransformmakescale(2, 2);                      }                      completion:^(bool finished){                      }]; } 

when run view zooms up, pixelated. it's pixelated because view has doubled in size it's resolution has not changed.

so, here's how not it.

- (void) makebig{      [uiview animatewithduration:0.5                           delay:0                         options:uiviewanimationoptionbeginfromcurrentstate                      animations:(void (^)(void)) ^{                          self.transform = cgaffinetransformmakescale(2, 2);                      }                      completion:^(bool finished){                          cgrect targetframe = self.frame;                          self.transform = cgaffinetransformidentity;                          self.frame = targetframe;                          [self setneedsdisplay];                      }]; } 

this works, fix visible @ end of animation when resolution snaps screen resolution. try pre-scaling view , pre-drawing @ final size scaling down , running animation scale again, various reasons can think of sounds totally stupid. suppose wrong , it's brightest idea since fire. kind of doubt though.

so how smooth scale of vector content done best?

view-based animation handy, if i'm not mistaken uses cabasicanimation, uses single keyframe. it'll little more code, if use cakeyframeanimation instead, core animation redraw contents of animated layer each keyframe (you specify when occur), can avoid appearance of pixelation.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -