我是编程,objective-c(和stackoverflow)的新手。我正在学习,并且进展缓慢;)但后来我遇到了一个谷歌无法解决的问题。我有一个窗口和一个NSview,然后添加了一个鼠标事件,该事件应该将坐标绘制到我的视图中,但事实并非如此。有趣的是:它是绘制当鼠标移过我的应用程序窗口的窗口按钮...通过鼠标事件绘制成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];
}
我不知道怎么去,有什么建议?谢谢!
此代码是什么?它看起来像你写了一个mouseDown处理程序。取决于代码的位置(例如,在应用程序中,或者在视图中或其他方面),它可能仅仅是在哪里它恰好是按钮的委托而不是视图。 – podperson 2013-02-21 22:18:59
它在视图中。我带了一个mouseDown处理程序,因为我想在我的视图中测试绘图,并且mousemove没有被调用。 – fw2601 2013-02-21 22:25:34
并且:我没有任何按钮,我的意思是3个OSX窗口按钮... – fw2601 2013-02-21 22:37:59