3

I have 2 sets of images. One set contains draggable ones and other is a static set. I have implemented drag-drop functionality for the draggable images. This is because the images needs to be dragged to static ones which contains matches. Now after placing the dragged image on the static one, there is nothing to do with it, hence I want to disable user interaction for image (since it's still draggable).

I have explored several solutions and SO questions here and there , but none of the solutions helped!

Can some one please help me how to remove dragging or user interaction for NSImageView?

Thanks everyone in advance :)

Community
  • 1
  • 1
Eshwar Chaitanya
  • 942
  • 2
  • 13
  • 34

2 Answers2

2

Create custom class of NSImageView and implement mouse entered and mouse exit method with empty definition

Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
  • Its not working, still image is draggable! Actually I have an image view(background) on the window. Then the set of images on it. Class of NSViewController is the file owner of it. However for our content view as u suggested created a subclass of NSImageView, then implemented mouse entered and mouse exited with empty definitions. Note: All the images and outlets are declared in files owner(NSViewController subclass). Still image is draggable :( – Eshwar Chaitanya Jul 15 '14 at 06:04
  • Instead removing the dragged image from array once the image is dropped solved the issue for me, thanks :) . Wonder why the solution you gave me doesn't work – Eshwar Chaitanya Jul 15 '14 at 07:52
-1

The easiest solution in my opinion is subclassing NSView. Your custom view should just contain an image variable you want to draw inside. After that you can use your custom view instead of default NSImageView, it will pass mouse events through.

Example:

class ImageView: NSView {

    var image: NSImage?

    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)
        if let image = image {
            image.draw(in: bounds)
        }
    }

}

Be noted that the target image will be scaled non-proportionally to your ImageView instance size.