Mac开发 拖拽事件NSDragOperation

在需要处理拖拽事件的控件中添加以下方法:

#pragma mark - NSDraggingDestination



- (NSDragOperation)draggingEntered:(id <NSDraggingInfo >)sender

{

NSPasteboard *pboard = [senderdraggingPasteboard];

NSArray *files = [pboardpropertyListForType:NSFilenamesPboardType];

for (NSString *filein files) {

CFStringRef UTI =UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridgeCFStringRef)file.pathExtension, NULL);

Boolean conforms =UTTypeConformsTo(UTI, kUTTypeImage);

if (UTI) CFRelease(UTI);

if (conforms)return NSDragOperationCopy;

}

returnNSDragOperationNone;

}



- (BOOL)prepareForDragOperation:(id <NSDraggingInfo >)sender

{

return YES;

}



- (BOOL)performDragOperation:(id <NSDraggingInfo >)sender

{

NSPasteboard *pboard = [senderdraggingPasteboard];

NSString *file = [pboardpropertyListForType:NSFilenamesPboardType][0];

self.image = [[NSImagealloc] initWithContentsOfFile:file];

return (self.image !=nil);

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于 jsplumb 连线的拖拽事件,可以通过以下步骤进行实现: 1. 给连线添加拖拽事件监听器: ```javascript jsPlumb.bind("connectionDrag", function(connection) { // 连线开始拖拽时的事件处理 }); jsPlumb.bind("connectionDragStop", function(connection) { // 连线拖拽结束时的事件处理 }); ``` 2. 在事件处理函数中,可以获取连线的起点和终点元素,以及连线本身的信息: ```javascript jsPlumb.bind("connectionDrag", function(connection) { var sourceId = connection.sourceId; // 连线起点元素的 ID var targetId = connection.targetId; // 连线终点元素的 ID var connectionId = connection.id; // 连线的 ID // 其他处理逻辑 }); jsPlumb.bind("connectionDragStop", function(connection) { var sourceId = connection.sourceId; // 连线起点元素的 ID var targetId = connection.targetId; // 连线终点元素的 ID var connectionId = connection.id; // 连线的 ID // 其他处理逻辑 }); ``` 3. 可以根据连线的起点和终点元素,进行相应的操作,比如更新元素的位置等: ```javascript jsPlumb.bind("connectionDrag", function(connection) { var sourceEl = $("#" + connection.sourceId); // 连线起点元素 var targetEl = $("#" + connection.targetId); // 连线终点元素 // 更新元素位置 sourceEl.css({ left: connection.endpoints[0].anchor.x * sourceEl.width(), top: connection.endpoints[0].anchor.y * sourceEl.height() }); targetEl.css({ left: connection.endpoints[1].anchor.x * targetEl.width(), top: connection.endpoints[1].anchor.y * targetEl.height() }); }); jsPlumb.bind("connectionDragStop", function(connection) { var sourceEl = $("#" + connection.sourceId); // 连线起点元素 var targetEl = $("#" + connection.targetId); // 连线终点元素 // 更新元素位置 sourceEl.css({ left: connection.endpoints[0].anchor.x * sourceEl.width(), top: connection.endpoints[0].anchor.y * sourceEl.height() }); targetEl.css({ left: connection.endpoints[1].anchor.x * targetEl.width(), top: connection.endpoints[1].anchor.y * targetEl.height() }); }); ``` 以上是实现 jsplumb 连线拖拽事件的基本步骤,具体的处理逻辑可以根据实际需求进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值