Mac アプリケーション用に円を描こうとしています。コードは次のとおりです。
- (void)mouseMoved:(NSEvent*)theEvent {
NSPoint thePoint = [[self.window contentView] convertPoint:[theEvent locationInWindow] fromView:nil];
NSLog(@"mouse moved: %f % %f",thePoint.x, thePoint.y);
CGRect circleRect = CGRectMake(thePoint.x, thePoint.y, 20, 20);
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSetRGBFillColor(context, 0, 0, 255, 1.0);
CGContextSetRGBStrokeColor(context, 0, 0, 255, 0.5);
CGContextFillEllipseInRect(context, CGRectMake(circleRect.origin.x, circleRect.origin.y, 25, 25));
CGContextStrokeEllipseInRect(context, circleRect);
[self needsDisplay];
}
- (void)mouseMoved:
完全に呼び出され、NSLog で正しい x 座標と y 座標を確認できます。しかし、円が表示されません...驚くべきことに、アプリケーションを最小化して再度開くと(NSViewが「更新」されると)円が完全に描画されます!