我有下面的代碼,後一個布爾是真實的我想一個繪圖添加到我的矩形。這裏是我有的代碼,但由於某些原因,它不是設置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