开发者

Dragging an NSTextField inside of a window

开发者 https://www.devze.com 2022-12-27 20:36 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号