我正在尝试为我的 iPhone 应用程序实现一些非常简单的线条绘制动画。我想在延迟后在我的视图上绘制一个矩形。我正在使用performSelector
运行我的绘图方法。
-(void) drawRowAndColumn: (id) rowAndColumn
{
int rc = [rowAndColumn intValue];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, currentColor.CGColor);
CGRect rect = CGRectMake(rc * 100, 100, 100, 100);
CGContextAddRect(context, rect);
CGContextDrawPath(context, kCGPathFillStroke);
}
然后通过以下方式调用:
int col = 10;
[self performSelector:@selector(drawRowAndColumn:)
withObject:[NSNumber numberWithInt:col]
afterDelay:0.2];
但似乎在drawRowAndColumn:
实际发送消息时,它不再有权访问有效的CGContextRef
,因为我收到以下错误:
<Error>: CGContextAddRect: invalid context
如果我用performSelector
直接调用替换drawRowAndColumn
,它工作正常。所以我的第一个想法是也传递CGContextRef
via performSelector
,但我似乎无法弄清楚如何同时传递多个参数(这是另一个好问题。)
上面的代码有什么问题?