Objective-C 绘图没有drawRect:形状不会显示

发布于 2024-11-14 21:33:19 字数 840 浏览 2 评论 0原文

我有一个名为mapWindow 的类,它连接到IB 中的一个窗口。

无论如何,我希望程序渲染的红色圆圈不会显示,除非代码位于drawRect下或者我移动窗口边框。甚至解锁和锁定焦点也不会更新窗口。

theOtherWindowView 实际上是一个连接到 IB 中自定义视图的 NSView。

- (void)test
{
    [theOtherWindowView lockFocus];
    NSBezierPath *path = [NSBezierPath bezierPath];
    NSPoint center = [self drawPoint];
    [path moveToPoint: center];
    [path appendBezierPathWithArcWithCenter:center
                                        radius:explosionRadius
                                    startAngle:0
                                    endAngle:360];
    [[NSColor redColor] set];
    [path fill];

    [theOtherWindowView unlockFocus];
}

不想想要使用drawRect,因为我想要多个实例而不是一个形状,其坐标每次更新都会改变。

我还尝试过 [self lockFocus][mapWindow lockFous]

I have a class called mapWindow which is hooked up to a window in IB.

No matter what, the red circle which I want the program to render won't show up unless the code is under drawRect or I move the window borders. Not even unlocking and locking the focus updates the window.

theOtherWindowView is actually a NSView hooked up to a custom view in IB.

- (void)test
{
    [theOtherWindowView lockFocus];
    NSBezierPath *path = [NSBezierPath bezierPath];
    NSPoint center = [self drawPoint];
    [path moveToPoint: center];
    [path appendBezierPathWithArcWithCenter:center
                                        radius:explosionRadius
                                    startAngle:0
                                    endAngle:360];
    [[NSColor redColor] set];
    [path fill];

    [theOtherWindowView unlockFocus];
}

I don't want to use drawRect because I want multiple instances not one shape that has it's coordinates changed every update.

I've also tried [self lockFocus] and [mapWindow lockFous]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ペ泪落弦音 2024-11-21 21:33:19

继续在 -drawRect: 中进行绘图。当发送 -drawRect: 时,您的视图的坐标系和剪切边界将会为您设置好,并且您的窗口的绘图上下文将是当前的。

在该方法中,根据需要绘制任意数量的圆圈。

Keep doing your drawing in -drawRect:. When -drawRect: is sent, your view's coordinate system and clipping boundaries will have been set up for you, and your window's drawing context will be the current one.

In that method, draw as many of these circles as you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文