2011-06-13 62 views
0

我有一个名为mapWindow的类,它连接到IB中的一个窗口。Objective-C无drawRect的绘图:形状不会显示

无论如何,除非代码位于drawRect下或我移动窗口边框,否则我想让程序渲染的红色圆圈不会显示出来。甚至没有解锁和锁定焦点更新窗口。

OtherWindowView实际上是一个连接到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]

回答

2

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

在该方法中,根据需要绘制尽可能多的这些圆。

+0

不,因为只能通过setNeedsDisplay调用drawrect:YES允许一个对象不能有多个副本。 – evdude100 2011-06-30 11:46:40

+0

你错了。 – NSResponder 2011-06-30 19:59:31

+0

非常感谢您的反馈,而不是测试代码? – evdude100 2011-07-01 19:12:45