如何在缩放时像 CALayer 一样流畅地绘制?
如第三张(最高)图像所示,白色边框是通过准确的anti-aliased
渲染绘制的。
然而,我的标签(即使我设置了contentScaleFactor
)和我的手绘圆圈(即使我打开anti aliasing
)都不是。
我怎样才能为 UIKit 组件或手绘图形进行抗锯齿渲染,这些图形可以像 CALayer 一样平滑地缩放比例?
有什么魔力?
白色边框是使用视图的 CALayer 绘制的:
self.layer.cornerRadius = frame.size.width / 2.0f ;
self.layer.borderColor = [UIColor whiteColor].CGColor ;
self.layer.borderWidth = 3.0f ;
这些数字是 UILabel 的
CGFloat contentScale = self.zoomScale * [UIScreen mainScreen].scale; // Handle retina
label.contentScaleFactor = contentScale;
并给出:
typedef struct {
CGRect rect ;
CGColorRef color ;
} EventColor ;
4 个圆圈是使用 CoreGraphics 绘制的
::CGContextSetAllowsAntialiasing(context, true) ;
::CGContextSetShouldAntialias(context, true) ;
// ...
EventColor ec = ...
// ...
::CGContextSetFillColorWithColor(context, ec.color) ;
::CGContextFillEllipseInRect(context, ec.rect) ;