我有一个NSView,我将添加为另一个NSView的子视图。我希望能够围绕父视图拖动第一个NSView。我有一些部分工作的代码,但NSView在我的鼠标拖动方向上沿Y轴的相反方向移动时出现问题。 (即,我拖下来,它向上和相反)。NSView:拖动视图
这里是我的代码:
// -------------------- MOUSE EVENTS ------------------- \\
- (BOOL) acceptsFirstMouse:(NSEvent *)e {
return YES;
}
- (void)mouseDown:(NSEvent *) e {
//get the mouse point
lastDragLocation = [e locationInWindow];
}
- (void)mouseDragged:(NSEvent *)theEvent {
NSPoint newDragLocation = [theEvent locationInWindow];
NSPoint thisOrigin = [self frame].origin;
thisOrigin.x += (-lastDragLocation.x + newDragLocation.x);
thisOrigin.y += (-lastDragLocation.y + newDragLocation.y);
[self setFrameOrigin:thisOrigin];
lastDragLocation = newDragLocation;
}
视图被翻转,虽然我改变了回默认,它似乎并没有发挥作用。我究竟做错了什么?