我有下面的代码,后一个布尔是真实的我想一个绘图添加到我的矩形。这里是我有的代码,但由于某些原因,它不是设置bool或调用setNeedsDisplay。我是否正确引用其他课程?感谢在不同的班级设置布尔
//在AppController.m
-(IBAction)colorToggle:(id)sender
{
if ([colorFilter state] == NSOnState)
{
CutoutView *theView = [[CutoutView alloc] init];
[theView setFilterEnabled:YES];
}
}
//在cutoutView.m
- (void)drawRect:(NSRect)dirtyRect
{
[[[NSColor blackColor]colorWithAlphaComponent:0.9]set];
NSRectFill(dirtyRect);
//this is what i want to be drawn when my bool is true and update the drawRect
if (filterEnabled == YES) {
NSRectFillUsingOperation(NSMakeRect(100, 100, 300, 300), NSCompositeClear);
[self update];
}
}
-(void)update
{
[self setNeedsDisplay:YES];
}
谢谢!这非常有意义 – 2012-04-04 04:14:51