问题描述
|
我在
drawRect:
方法中有一些代码,可以从数组中绘制一系列的圆。我可以验证这些点在内存中保留的时间足够长,并且可以到达应绘制它们的位置。但是,似乎NSBezierPath
的fill
方法没有画圆。
这是我的drawRect:
- (void)drawRect:(NSRect)dirtyRect
{
NSPoint aPoint;
NSRect aRect = NSMakeRect(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];
}
}
我有另一种方法“ 5”,将点添加到数组中
- (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当前位置指示器非常相似。任何对此的见解也将不胜感激。
解决方法
检查您的点,并确保没有倒置的矩形,并且您的X / Y坐标是您所期望的。确保锚点和坐标正确相对。
使用苹果开发人员工具附带的称为Quartz Debug的工具可能会对您有所帮助。它在/ Developer / Applications / Graphics Tools /文件夹中。启动此工具后,转到“工具”菜单,然后打开“ Flash屏幕更新”。这将使您了解何时重新绘制内容。
希望对您有所帮助。
,我已复制粘贴您的视图代码。我将此粘贴在应用程序委托中进行测试。 here7ѭ是此处的自定义视图(对reflection8ѭ的错误反应是,不会对您造成不良影响),这两个窗口都是在IB中创建的,WebView同样也位于IB的父窗口中。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// badWindow is an IBOutlet to the overlay window,parentWindow an IBOutlet
// to the window with the webview,myWebView an IBOutlet to the webview
BadView * myBadView = [[BadView alloc] initWithFrame:[[badWindow contentView] frame]];
// Create some random points for testing
[myBadView createArrayOfPoints];
[badWindow setStyleMask:NSBorderlessWindowMask];
[badWindow setOpaque:NO];
[badWindow setAlphaValue:0.9]; // Will still act opaque without this
[badWindow setHasShadow:NO];
[badWindow setContentView:myBadView];
[parentWindow addChildWindow:badWindow ordered:NSWindowAbove];
[[myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:
[NSURL URLWithString:@\"http://www.apple.com/\"]]];
[myBadView release];
}