【问题标题】:osx Drag not workingosx拖动不起作用
【发布时间】:2015-06-02 12:09:39
【问题描述】:

我想创建一个使用 swift 进行拖动操作的最小工作示例。但是,到目前为止,这并不奏效。没有调用任何 NSDraggingDestination 函数,但我无法发现我的错误:(

class DragView : NSView , NSDraggingDestination {


required init?(coder: NSCoder) {
    println("init")
    super.init(coder: coder)
    let theArray = NSImage.imageFileTypes()
    self.registerForDraggedTypes(theArray)
}

override func draggingEntered(sender: NSDraggingInfo) -> NSDragOperation {
    println("draggingEntered")
    return NSDragOperation.Copy
}


override func draggingUpdated(sender: NSDraggingInfo) -> NSDragOperation {
    println("draggingUpdated")
    return NSDragOperation.Copy
}

override func prepareForDragOperation(sender: NSDraggingInfo) -> Bool {
    println("prepareForDragOperation")
    return true
}
}

【问题讨论】:

    标签: macos swift drag-and-drop


    【解决方案1】:

    NSImage.imageFileTypes() 不是self.registerForDraggedTypes 的有效数组。

    [NSFilenamesPboardType] 为例。

    required init?(coder: NSCoder) {
        println("init")
        super.init(coder: coder)
        self.registerForDraggedTypes([NSFilenamesPboardType])
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-03
      • 1970-01-01
      • 2015-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      相关资源
      最近更新 更多