MacRuby应用程序中的拖动事件出现问题
我已经有一段时间没有做任何Cocoa开发了,我正试图让这个非常快速、肮脏(简单)的应用程序结束。我决定使用MacRuby,因为它是学习它的一个很好的借口,而且这个应用程序非常简单,很有意义 不过,我在获取自定义视图以响应拖动事件时遇到问题MacRuby应用程序中的拖动事件出现问题,ruby,cocoa,macruby,Ruby,Cocoa,Macruby,我已经有一段时间没有做任何Cocoa开发了,我正试图让这个非常快速、肮脏(简单)的应用程序结束。我决定使用MacRuby,因为它是学习它的一个很好的借口,而且这个应用程序非常简单,很有意义 不过,我在获取自定义视图以响应拖动事件时遇到问题 class ImportPanel < Panel def initWithFrame(frame) registerForDraggedTypes(NSArray.arrayWithObjects(NSPasteboardTypeSound
class ImportPanel < Panel
def initWithFrame(frame)
registerForDraggedTypes(NSArray.arrayWithObjects(NSPasteboardTypeSound, nil))
super(frame)
end
def mouseDown(event)
NSLog('click')
end
def draggingEntered(sender)
NSLog('drag')
end
end
类导入面板
在本例中,面板只是添加边框的NSView。此自定义视图(ImportPanel)正确响应单击事件,但对拖动事件完全没有反应。我为RegisterForDragedTypes:尝试了几种不同的粘贴板类型和配置,但似乎都没有产生任何结果。这段代码对我很有用
AppDelegate.rb
class AppDelegate
attr_accessor :window
attr_accessor :panel
def applicationDidFinishLaunching(a_notification)
# nothing special here
end
def initialize
@panel = Panel.new
# Just for debug
puts @panel
end
end
这是我的播放器.rb
:
class Panel < NSView
def awakeFromNib
registerForDraggedTypes(NSArray.arrayWithObjects(NSFilenamesPboardType, NSURLPboardType, NSStringPboardType, nil))
end
def mouseDown(event)
NSLog('click')
end
def draggingEntered(sender)
NSLog('drag')
return NSDragOperationNone
end
end
类面板
拖拽类型的数组,它可以帮助我测试不同的拖拽操作(URL、文件等)。请注意,Draggingered需要返回一个NSDragOperation
我使用了NSDragOperationNone
来查看它是否工作