0

Let me elaborate the steps i am doing

  1. Create Mac 10.9 Project
  2. Drag a CustomView (Let's call it myView) to the .xib
  3. Drag a NSButton to the .xib but out side the CustomView
  4. Now programatically (using a other class) i add a NSTextField to the CustomView when the button is clicked by this code

    NSTextField *textField = [[NSTextField alloc] init]; [textField setBezeled:NO]; [textField setEditable:NO]; [textField setSelectable:NO]; [textField setFont:[NSFont fontWithName:@"Arial" size:20]]; [textField setStringValue:@"Hello World!"]; int textWidth = textField.fittingSize.width; int textHeight = textField.fittingSize.height; [textField setFrame:NSMakeRect(0, 0, textWidth, textHeight)]; [myView addSubview:textField];

  5. Now i see that the TestField is added to myView

  6. All i want is the user can drag the textField movable inside myView

i added the following code

- (void)mouseDown:(NSEvent *)event{
    NSLog(@"Hi");
}

But the NSLog is not getting shown

How do i make the NSTextField draggable?

4

1 回答 1

0

注意:因为鼠标移动事件发生得如此频繁,以至于它们可以迅速淹没事件调度机制,默认情况下 NSWindow 对象不会从全局 NSApplication 对象接收它们。但是,您可以通过向 NSWindow 对象发送带有 YES 参数的 setAcceptsMouseMovedEvents: 消息来专门请求这些事件。

来自Apple 文档集

于 2013-12-17T20:37:24.977 回答