我有以下代码:
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
// Left frame.
CGContextAddRect(context, CGRectMake(0, 0,
frameWidth,
self.frameHeight));
CGContextSetFillColorWithColor(context, [UIColor colorWithRed:frameBorderColorRed
green:frameBorderColorGreen
blue:frameBorderColorBlue
alpha:frameBorderColorAlpha].CGColor);
CGContextFillPath(context);
CGContextAddRect(context, CGRectMake(frameBorderWidth,
frameBorderWidth,
frameWidth - (2*frameBorderWidth),
self.frameHeight - (2*frameBorderWidth)));
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextFillPath(context);
// Right frame.
CGContextAddRect(context, CGRectMake(frameWidth + distanceBetweenFrames,
0,
frameWidth,
self.frameHeight));
CGContextSetFillColorWithColor(context, [UIColor colorWithRed:frameBorderColorRed
green:frameBorderColorGreen
blue:frameBorderColorBlue
alpha:frameBorderColorAlpha].CGColor);
CGContextFillPath(context);
CGContextAddRect(context, CGRectMake(frameWidth + distanceBetweenFrames + frameBorderWidth,
frameBorderWidth,
frameWidth - (2*frameBorderWidth),
self.frameHeight - (2*frameBorderWidth)));
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextFillPath(context);
}
左框显示但右框不显示。但是,如果我要将左框架注释掉,则会显示右框架。我也尝试在文档中绘制线条:
无济于事。
答案 0 :(得分:0)
我会考虑使用CoreAnimation,因为它使用GPU。 除了问题是您通过以下方式关闭当前路径:
CGContextFillPath(context);
然后尝试使用:
CGContextAddRect
正如文档所说:“添加一条到当前路径的矩形路径。”
您需要使用以下方法添加其他路径:
CGContextMoveToPoint
您可以在此处阅读更多详细信息: https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGContext/index.html