NSWindow的dragImage的例子?

发布于 2024-11-09 09:42:16 字数 283 浏览 0 评论 0原文

我正在寻找 NSWindow 的 DragImage 方法的解释。

- (void)dragImage:(NSImage *)image at:(NSPoint)imageLocation offset:(NSSize)pointerOffset event:(NSEvent *)event pasteboard:(NSPasteboard *)pasteboard source:(id)sourceObject slideBack:(BOOL)slideBack

有什么帮助吗?

I'm looking for an explanation of NSWindow's dragImage method.

- (void)dragImage:(NSImage *)image at:(NSPoint)imageLocation offset:(NSSize)pointerOffset event:(NSEvent *)event pasteboard:(NSPasteboard *)pasteboard source:(id)sourceObject slideBack:(BOOL)slideBack

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纸短情长 2024-11-16 09:42:16

该方法的 NSView 文档提供了更详细的解释,包括示例代码。这两种方法之间的唯一区别是 imageLocation 所在的坐标系。在 http://developer.apple.com/library/mac/documentation/Cocoa/Reference /ApplicationKit/Classes/NSView_Class/Reference/NSView.html#//apple_ref/doc/uid/20000014-SW135

编辑:以下是该链接中的示例代码,并添加了注释。

- (void)mouseDown:(NSEvent *)theEvent {
    // Create an offset for the offset parameter. Since it is ignored, you should just use 0,0.
    NSSize dragOffset = NSMakeSize(0.0, 0.0);
    NSPasteboard *pboard;

    // Get the pasteboard used to hold drag-and-drop data
    pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
    // Declare the data type used on the pasteboard. This sample passes a TIFF representation of an image
    [pboard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType]  owner:self];
    // Add the data to the pasteboard.
    [pboard setData:[[self image] TIFFRepresentation] forType:NSTIFFPboardType];
    // Call dragImage:... with:
    // An image representing the object you are dragging. This could be a file's icon or a screenshot of a view, etc.
    [self dragImage:[self image]
    // The starting location of the image in this views coordinates. This should be close to the location of the object you are dragging.
                 at:[self imageLocation]
    // An NSSize structure. This is not used.
             offset:dragOffset
    // The mousedown event
              event:theEvent
    // The pasteboard which contains the data
         pasteboard:pboard
    // The object providing the data
             source:self
    // Whether or not the image should slide to its starting location if the drag isn't completed.
          slideBack:YES];

}

源对象(在本例中为 self )需要实现 NSDraggingSource 协议。您可能还对 NSPasteboard 类参考。

The NSView documentation of that method provides a much more detailed explanation, including example code. The only difference between the two methods is the coordinate system that imageLocation is in. Find it at http://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html#//apple_ref/doc/uid/20000014-SW135

Edit: Here is the sample code from that link, with added comments.

- (void)mouseDown:(NSEvent *)theEvent {
    // Create an offset for the offset parameter. Since it is ignored, you should just use 0,0.
    NSSize dragOffset = NSMakeSize(0.0, 0.0);
    NSPasteboard *pboard;

    // Get the pasteboard used to hold drag-and-drop data
    pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
    // Declare the data type used on the pasteboard. This sample passes a TIFF representation of an image
    [pboard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType]  owner:self];
    // Add the data to the pasteboard.
    [pboard setData:[[self image] TIFFRepresentation] forType:NSTIFFPboardType];
    // Call dragImage:... with:
    // An image representing the object you are dragging. This could be a file's icon or a screenshot of a view, etc.
    [self dragImage:[self image]
    // The starting location of the image in this views coordinates. This should be close to the location of the object you are dragging.
                 at:[self imageLocation]
    // An NSSize structure. This is not used.
             offset:dragOffset
    // The mousedown event
              event:theEvent
    // The pasteboard which contains the data
         pasteboard:pboard
    // The object providing the data
             source:self
    // Whether or not the image should slide to its starting location if the drag isn't completed.
          slideBack:YES];

}

The source object (self in this case) needs to implement the NSDraggingSource protocol. You may also be interested in the NSPasteboard Class Reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文