Quartz2D for OSX没有绘制任何东西

时间:2014-01-11 05:03:47

标签: cocoa graphics quartz-2d

我正在尝试绘制到屏幕上,但它无法正常工作。我想我错过了一些联系。最大的问题是我找到了一百万个iOS教程,但对Mac OSX没有任何帮助!很沮丧。屏幕截图显示了我如何设置项目...我正在使用XCode 5.

Created a custom view

我创建了一个名为MyQuartzView的类,它是NSView的子类。这是我在MyQuartzView.m中的列表:

#import "MyQuartzView.h"

@implementation MyQuartzView

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

    }
    return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
    [super drawRect:dirtyRect];

    // Drawing code here.
    CGContextRef myContext = [[NSGraphicsContext currentContext] graphicsPort];
    NSLog(@"%@", myContext);
    CGContextSetRGBFillColor (myContext, 1, 0, 0, 1);
    CGContextFillRect (myContext, CGRectMake (0, 0, 200, 100 ));
    CGContextSetRGBFillColor (myContext, 0, 0, 1, .5);
    CGContextFillRect (myContext, CGRectMake (0, 0, 100, 200));
}

@end

我在MyQuartzView.h中没有任何代码。

我被卡住了......请帮忙!提前谢谢!

1 个答案:

答案 0 :(得分:1)

没关系,我明白了。我只是忘了通过Xcode接口部分的“Identity Inspector”将我拖到我的窗口上的自定义视图连接到我的MyQuartzView类。