我有一個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;
}
視圖被翻轉,雖然我改變了回默認,它似乎並沒有發揮作用。我究竟做錯了什麼?