gpt4 book ai didi

iphone - 在核心图形中绘制阴影很慢

转载 作者:行者123 更新时间:2023-12-01 19:13:55 25 4
gpt4 key购买 nike

我有以下代码在我的 UIView drawRect 上绘制内部阴影:

//add some inner shadow to the card box
CGContextSaveGState(context);

CGMutablePathRef cardPath = CGPathCreateMutable();
CGPathAddRect(cardPath, NULL, CGRectInset(mainRect, -42, -42));
CGPathAddPath(cardPath, NULL, mainPathRef);
CGPathCloseSubpath(cardPath);

// Add the visible paths as the clipping path to the context
CGContextAddPath(context, mainPathRef);
CGContextClip(context);

// Now setup the shadow properties on the context
UIColor *innerShadowColor = [UIColor colorWithWhite:133/255.f alpha:1.0];
CGContextSetShadowWithColor(context, CGSizeMake(0.0f, 1.0f), 30.0f, [[UIColor orangeColor] CGColor]);

// Now fill the rectangle, so the shadow gets drawn
[innerShadowColor setFill];
CGContextSaveGState(context);
CGContextAddPath(context, cardPath);
CGContextEOFillPath(context);
CGContextRestoreGState(context);

// Release the paths
CGPathRelease(cardPath);

CGContextRestoreGState(context);

CGPathRelease(mainPathRef);

问题是这真的很慢。有什么办法可以加快这段代码的速度吗?

最佳答案

如果可能的话,我会在图像编辑器中创建阴影,将其保存为 png,然后根据需要调整大小和平铺。

另一个想法是使用 shouldRasterize CALayer 的属性(property).它将缓存绘图结果并在您的 View 保持不变时使用它。在这种情况下,性能取决于您修改 View 内容的频率。

关于iphone - 在核心图形中绘制阴影很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14535257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com