从CAShapeLayer获得真正糟糕的表现

Ser*_*nce 1 iphone graphics performance cocoa-touch ios

我有一个存储在一个大文件中的图形,并分解为很多mutablePaths如下:

mutablePath = CGPathCreateMutable();
CGPathMoveToPoint(mutablePath, NULL, 123.70,49.23);
CGPathAddCurveToPoint(mutablePath, NULL, 124.57,54.05,124.06,58.98,123.43,63.80);
CGPathAddCurveToPoint(mutablePath, NULL, 123.09,66.42,122.70,69.03,122.43,71.66);
CGPathAddCurveToPoint(mutablePath, NULL, 121.64,81.02,121.35,83.58,120.92,86.11);
CGPathCloseSubpath(mutablePath);
CGPathAddPath(outlineMutablePath, NULL, mutablePath);
CGPathRelease(mutablePath);
Run Code Online (Sandbox Code Playgroud)

我将所有路径合并为4-5路径CGPathAddPath,然后将每个路径添加到a CAShapeLayer.我附上CAShapeLayers如下视图:

for (int i = 0; i < [_graphic.shapeLayers count]; i++)
{
    [self.layer addSublayer:[_graphic.shapeLayers objectAtIndex:i]];
}
Run Code Online (Sandbox Code Playgroud)

正确地绘制图形,但是,当我在图形所在的同一屏幕上拉出模态视图时,模态视图在屏幕上显示时会非常糟糕.还注意到它需要花费相当多的时间来绘制形状,并且当我试图离开它并转到不同的导航控制器时,通常看起来似乎会压低屏幕.在运行时间配置文件时,我注意到花费的大部分时间都在CALayer layoutSublayersCALayer drawInContext.

图形确实有很多路径,但不是那么复杂,我认为iOS绘制它应该有这么多麻烦.当我在drawRect中手动绘制这些路径时,我没有得到这种效果.另外,专家告诉我,以这种方式绘制图形会更好.这让我相信我在某处做错了什么.

Bar*_*ski 6

尝试将shouldRasterize属性设置YES为全部CAShapeLayersself.layer.