我有以下代码在我的 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);
问题是这真的很慢。有什么办法可以加快这段代码的速度吗?