How can I programmatically make an NSView so that the user can move its position with the mouse? What properties do i need to assign to the view? thanks!
newView = [helpWindow contentView];
[contentView addSubview:newView];
//add properties of newView to be able to respond to touch and can be draggable
Unfortunately, there’s no simple way like setMoveByWindowBackground: that you can do with a window. You have to override mouseDown:, mouseDragged:, and mouseUp: and use setFrameOrigin: based on the position of the mouse pointer. In order not have the view jump when you first click inside it, you also need to account for the offset between the view’s origin and where the moue pointer is in the view when you first click. Here is an example that I made in a project to move “tiles” around in a parent view (this was for a computer version of the game “Upwords”, which is like 3d scrabble).
This example points out one more possible complication. As you move a view around, it may appear to move underneath other views, so I take care of that my making the moving view the top most view of the parent view’s subviews (viewsList is the array gotten from self.subviews)