我有一个openGl视图的子类。在其中一种方法中,我设置了一个标记来绘制背景黑色或白色。在方法结束时,我调用setNeedsDisplay。永远不会被称为!我在mouseDownEvent中也有一个setNeedsDisplay。当我点击视图IT CALLS IT!我的背景改变了颜色。有任何想法吗?这是代码。
在openGL视图中
-(long)setBackgroundBlack:(BOOL)flag{
if(flag == YES){
blkBg = YES;
[self setNeedsDisplay:YES];
}else if (flag == NO){
blkBg = NO;
[self setNeedsDisplay:YES];
}
if (flag == blkBg){
return 0;
}else{
return 1;
}
}
- (void)mouseDown:(NSEvent *)theEvent
{
lastDragLocation = [[self superview] convertPoint:[theEvent locationInWindow] fromView:nil];
NSPoint newPoint;
newPoint.x = lastDragLocation.x * (2.0 / self.bounds.size.width) - 1.0;
newPoint.y = lastDragLocation.y * (2.0 / self.bounds.size.width) - 1.0;
[self setNeedsDisplay:YES];
}
-(IBAction)claim1931BW:(id)sender{
long res = [_myPlotView setBackgroundBlack:NO];
NSLog(@"%ld", res);
[self.cie1931BWMenu setState:NSOnState];
[self.cie1931ColorMenu setState:NSOffState];
}