mouseUp无法在Cocoa中启动? [英] mouseUp not firing in Cocoa?

查看:53
本文介绍了mouseUp无法在Cocoa中启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的应用程序中实现拖放功能,但遇到了mouseUp事件无法触发的问题.如果我只是单击并释放视图,则射击就很好了,但是如果我拖动,鼠标就会拖动事件触发,仅此而已.

I'm trying to implement drag&drop functionality in my app and I ran into a problem of my mouseUp event not firing. It fires just fine if I simply click and release on my view, but if I do drag, my mouseDragged event fires and that's it.

通过尝试不同的方法,我发现问题出在我的dragImage调用中,但是我暂时不知道如何解决它.

By trying different things I figured out that the problem is in my dragImage call, but I don't know how to solve it for now.

这是我的代码:

-(void) mouseDragged:(NSEvent *)theEvent
{
   isDragging = YES;

   if ([selectedCellRowIndex longValue] >= 0)
   {
      NSImage *im = [[NSImage alloc]initWithContentsOfFile:@"/Users/UserName/Desktop/drag.png"];
      NSSize dragOffset = NSMakeSize(0.0, 0.0);
      NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];

      [pboard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType]  owner:self];
      [pboard setData:[im TIFFRepresentation] forType:NSTIFFPboardType];

      [self dragImage:im
                   at:downPointRelativeToTable
               offset:dragOffset
                event:theEvent
           pasteboard:pboard
               source:self
            slideBack:YES];
  }
} 

有人知道我的问题在哪里吗?!谢谢!

Does anyone know where my problem can be?! Thank you!

推荐答案

在您的代码段中,您将获得 NSPasteboard 实例,但未将数据复制到该实例.这是必需的,否则您的拖动操作将无法正确启动-这可能就是为什么您永远不会收到 mouseUp:事件的原因.

In your code snippet you're getting the NSPasteboard instance but not copying your data to it. That's required, otherwise your drag won't be initiated properly - that's probably why you'll never get the mouseUp: event.

在调用此方法之前,必须放置要传输的数据在板上.为此,请获取拖动粘贴板对象(NSDragPboard),声明数据的类型,然后将数据放到粘贴板.

Before invoking this method, you must place the data to be transferred on pboard. To do this, get the drag pasteboard object (NSDragPboard), declare the types of the data, and then put the data on the pasteboard.

这篇关于mouseUp无法在Cocoa中启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆