Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
I have an NSImageView that I need to drag it around. I know to use the mouseDragged: method in the NSImageView subclass. I looked in the Apple Documentation and I didn't see a property or method for getting the NSImageView's position. How can I use the mouseDragged: method so the user can drag the NSImageView only horizontally and vertically. The movement will also need to be animated.
Thanks!
 
I figured out how to move it around, but I don't know how to only allow horizontal and vertical movement (No moving it in circles and diagonal movement).
Please Help
Thanks
 
Look up NSDraggingSource Protocol in the AppKit reference section. There is a method in there that might serve your need. However, AFAIK, you cannot constrain the cursor itself, the OS simply does not allow that (directly, at least), you will only be able to constrain the motion of the drag image.
 
I just want to limit the movement to up/down and side-to-side.
I am using this to allow the dragging movement:
Code:
- (void)mouseDown:(NSEvent *)theEvent
{
	    lastDragLocation = [theEvent locationInWindow]; 
}

-(void)mouseDragged:(NSEvent *)theEvent{


    NSPoint newDragLocation = [theEvent locationInWindow];
    NSPoint origin = [self frame].origin;
    origin.x += (-lastDragLocation.x + newDragLocation.x);
    origin.y += (-lastDragLocation.y + newDragLocation.y);
    [self setFrameOrigin:origin];
    lastDragLocation = newDragLocation;

}
How could I modify this to only allow left/right and up/down movement?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.