我是编程、objective-c(和stackoverflow)的新手。我正在学习并非常缓慢地前进;)但后来我遇到了一个谷歌无法解决的问题。我有一个窗口和一个 NSview,然后添加了一个鼠标事件,应该将坐标绘制到我的视图中,但它没有。有趣的是:它是在鼠标移到我的应用程序窗口的窗口按钮上时绘制的......
- (void)drawRect:(NSRect)dirtyRect {
NSPoint imagePos = NSMakePoint(0, 0);
NSImage *aImage = [NSImage imageNamed:@"mw_bg01.png"];
[aImage dissolveToPoint:imagePos fraction:1.0];
}
- (void)mouseDown:(NSEvent*)theEvent;{
mouseLoc = [NSEvent mouseLocation];
mousePosX = mouseLoc.x;mousePosY = mouseLoc.y;
NSString* mouseString = [NSString stringWithFormat:@"%d", mousePosX];
NSPoint textPoint = NSMakePoint(5, 5);
NSMutableDictionary *textAttrib = [[NSMutableDictionary alloc] init];
[textAttrib setObject:[NSFont fontWithName:@"Helvetica Light" size:10]
forKey:NSFontAttributeName];
[textAttrib setObject:[NSColor grayColor] forKey:NSForegroundColorAttributeName];
[mouseString drawAtPoint:textPoint withAttributes:textAttrib];
}
我不知道怎么继续,有什么建议吗?谢谢!