【问题标题】:How to make a NSTextField added to a NSView Draggable如何将 NSTextField 添加到 NSView Draggable
【发布时间】:2013-11-08 04:28:15
【问题描述】:

让我详细说明我正在执行的步骤

  1. 创建 Mac 10.9 项目
  2. 将 CustomView(我们称之为 myView)拖到 .xib 中
  3. 将 NSButton 拖到 .xib 但在 CustomView 之外
  4. 现在以编程方式(使用其他类)当此代码单击按钮时,我将 NSTextField 添加到 CustomView

    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. 现在我看到 TestField 已添加到 myView 中

  6. 我想要的只是用户可以在 myView 中拖动可移动的 textField

我添加了以下代码

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

但是没有显示 NSLog

如何使 NSTextField 可拖动?

【问题讨论】:

    标签: events mouseevent nsview nsevent


    【解决方案1】:

    注意:因为鼠标移动事件发生得如此频繁,以至于它们可以 快速淹没事件调度机制,一个 NSWindow 对象 默认不从全局 NSApplication 对象接收它们。 但是,您可以通过发送 NSWindow 对象 setAcceptsMouseMovedEvents: 带有 是的论点。

    来自Apple Docset

    【讨论】:

      猜你喜欢
      • 2012-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-22
      • 2020-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多