objective c - What does CALayer know that I do not when zooming -
how can draw smoothly calayer while zooming?
as seen in third (tallest) image white border drawn accurate, anti-aliased
rendering.
however neither labels (even though set contentscalefactor
) nor hand drawn circles (even though turn anti aliasing
on) are.
how can have anti-aliased rendering either uikit components or hand-drawn graphics scale zooming factor smoothly calayer does?
what's magic?
the white border drawn using view's calayer:
self.layer.cornerradius = frame.size.width / 2.0f ; self.layer.bordercolor = [uicolor whitecolor].cgcolor ; self.layer.borderwidth = 3.0f ;
the numbers uilabel's
cgfloat contentscale = self.zoomscale * [uiscreen mainscreen].scale; // handle retina label.contentscalefactor = contentscale;
and given:
typedef struct { cgrect rect ; cgcolorref color ; } eventcolor ;
the 4 circles drawn using coregraphics
::cgcontextsetallowsantialiasing(context, true) ; ::cgcontextsetshouldantialias(context, true) ; // ... eventcolor ec = ... // ... ::cgcontextsetfillcolorwithcolor(context, ec.color) ; ::cgcontextfillellipseinrect(context, ec.rect) ;
it turns out misunderstood contentscalefactor
meant for, , discovered after calayer's contentscale
.
the upshot drawrect
method in whatever uiview subclass can go ahead , pretend zooming scale set 1.0 provided view's layer's contentscale set reflect current zoom level of scroll view.
- (void) scrollviewdidendzooming: (uiscrollview *) scrollview withview: (uiview *) view atscale: (float) scale { scale *= [uiscreen mainscreen].scale ; (uiview * v in view.subviews) { v.layer.contentsscale = scale ; [v setneedsdisplay] ; } }
the example above assumes scroll view contains non opaque container view in turn contains every actual views layer.contentscale
needs adjusting.
Comments
Post a Comment