배열에서 일련의 원을 그리는 drawRect:
메서드에 일부 코드가 있습니다. 나는 그 포인트들이 충분히 오래 메모리에 머물러 있는지, 그리고 그 포인트들이 그려 져야 하는지를 확인할 수있다. 그러나 NSBezierPath
의 fill
메서드가 원을 그리지 않는 것처럼 보입니다. 여기 이 호출되었지만 드로잉되지 않습니다.
drawRect:
- (void)drawRect:(NSRect)dirtyRect
{
NSPoint aPoint;
NSRect aRect = NSMakeRect(0, 0, 6, 6);
// Erase the rectangle
[[NSColor clearColor] set];
NSRectFill([self bounds]);
// Draw the dots
[[NSColor colorWithCalibratedRed:(77.0/255.0) green:(11.0/255.0) blue:(11.0/255.0) alpha:1.0] set];
for(NSValue *aValuePoint in arrayOfPoints) {
aPoint = [aValuePoint pointValue];
aRect.origin.y = aPoint.y - aRect.size.height/2.0;
aRect.origin.x = aPoint.x - aRect.size.width/2.0;
// The code does get to this point, it does not draw however...
[[NSBezierPath bezierPathWithOvalInRect:aRect] fill];
}
}
나는 배열에 포인트를 추가 할 다른 방법 drawDotAtPoint:
이
- (void)drawDotAtPoint:(NSPoint)aPoint
{
NSLog(@"drawDotAtPoint:(%f, %f)", aPoint.x, aPoint.y);
[arrayOfPoints addObject:[NSValue valueWithPoint:aPoint]];
// I've also tried using [self superview] instead of just self
[self setNeedsDisplay: YES];
}
그리고 나는이 방법이 올바른에서 호출되어 있는지 확인 할 수 있는데도 시간 (또는 그렇게 보입니다) 초기 drawRect 후 그림이 없습니다.
사이드 노트 : 내 목표는 실제로 한 점을 그리고 그 주위에 링이 나타나 확대하고 사라집니다. 지도 앱에서 iOS의 GPS 현재 위치 표시기와 매우 유사합니다. 그것에 대한 통찰력은 또한 평가 될 것입니다.
이 코드는 완벽하게 작동합니다.보기를 어떻게 작성하고 있습니까? –
윈도우의 contentView로 설정하고 있습니다 : [self setContentView : [[VisualEventView alloc] initWithFrame : [[self contentView] frame]]]]; – TheCrypticAce
아직도 나를 위해 일해 ... for 루프의 내부에서'[self canDraw]'는 무엇을 말합니까? 또한, 두 가지 메모 : 나는'clearColor'가 당신이 생각하는대로하지 않는다고 생각합니다. 투명합니다. (''NSEraseRect') (http://developer.apple.com/library/mac/documentation/Cocoa /Reference/ApplicationKit/Miscellaneous/AppKit_Functions/Reference/reference.html#//apple_ref/c/func/NSEraseRect)); 스타일/컨벤션의 문제로, 당신의 방법은 실제로 드로잉을하지 않으면 'draw ...'로 시작해서는 안됩니다. –