Disable user interaction for NSImageView

﹥>﹥吖頭↗ 提交于 2019-12-10 22:59:29

问题


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 :)


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/24734940/disable-user-interaction-for-nsimageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!