Im attempting to make a little app that lets you add text boxes to you canvas (window). I have an NSTextField that needs to let you drag it around the window. When you drop it it needs to stay in the spot you mouse left it. Heres my code to make the fist text field:
N开发者_如何学JAVASTextField *myTextField=[[NSTextField alloc] initWithFrame:NSMakeRect(200.0, 200.0, 200.0, 25.0)];
[myTextField setBordered:NO];
[myTextField setStringValue:@"Double Click to edit"];
[[window contentView] addSubview:myTextField];
//Some sort of dragging code for myTextField
If anyone has ever done something like this any help is really appreciated.
My first instinct would be to create a subclass of NSTextField
and override some or all of mouseDown:
, mouseDragged:
, and mouseUp:
to create the dragging behavior you want. The mouse events section in Apple's Event-Handling Guide might be helpful.
精彩评论