被叫但不画画
我在 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 当前位置指示器非常相似。对此的任何见解也将不胜感激。
I have some code in the drawRect:
method that draws a series of circles from an array. I can verify that the points stay in memory long enough and get to the point where they should be drawn. However, it seems as if the fill
method of NSBezierPath
is not drawing the circles.
Here is my 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];
}
}
I have another method drawDotAtPoint:
where I add the points to an array
- (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];
}
And while I am able to verify that these methods are called at the correct times (or so it seems) no drawing after the initial drawRect: will take place
Sidenote:
My goal is to actually draw a point and have a ring appear around it, enlarge and fade out. Much similar to the GPS current location indicator on iOS, in the Maps app. Any insight on that would also be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查您的点并确保您没有倒置的矩形并且您的 X/Y 坐标符合您的预期。确保您的锚点和坐标正确相对。
使用苹果开发者工具附带的名为 Quartz Debug 的工具可能会对您有所帮助。它位于 /Developer/Applications/Graphics Tools/ 文件夹中。启动此工具后,转到“工具”菜单并打开“Flash Screen Updates”。这将使您了解何时重新绘制或不重新绘制事物。
希望对一些人有所帮助。
Check your points and make sure that you don't have an inverted rectangle and that your X/Y coords are what you expect. Make sure that your anchor point and coordinates are correctly relative.
You may be helped along a bit by using a tool called Quartz Debug that comes with apple's developer tools. It is in the /Developer/Applications/Graphics Tools/ folder. After starting this tool, go to the "tools" menu and turn on "Flash Screen Updates". This will give you an idea of when things are being redrawn or not.
Hope that helps some.
我已经复制粘贴了您的查看代码。我将其放在应用程序委托中进行测试。
BadView
是这里的自定义视图(对你没有任何影响 - “Bad”,因为它的行为不正确:)
)窗口都是在 IB 中创建的,并且 WebView 也同样放置在 IB 的父窗口中。I've copy-pasted your view code. I stuck this in an app delegate for testing.
BadView
is the custom view here (no reflection on you -- "Bad" because it's misbehaving:)
) The windows are both created in IB, and the WebView is likewise placed in the parent window in IB.