【发布时间】:2014-01-11 13:15:45
【问题描述】:
我正在尝试在屏幕上绘图,但它不起作用。我想我错过了一些联系。最大的问题是我找到了一百万零一个 iOS 教程,但对于 Mac OSX 却一无所获!非常令人沮丧。屏幕截图显示了我是如何设置项目的……我使用的是 XCode 5。
我创建了一个名为 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 中没有任何代码。
我被困住了……请帮忙!提前致谢!
【问题讨论】: