NSImageView双击动作 [英] NSImageView double click action

查看:235
本文介绍了NSImageView双击动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Mac App中有一些NSImageView,用户可以在其中拖放诸如.png或.pdf之类的对象,以将其存储到用户共享默认值"中,效果很好.

I have some NSImageView in my Mac App where the user can drag'n drop objects like .png or .pdf, to store them into User Shared Defaults, that works fine.

我现在想为用户双击这些NSImageView时设置一个动作,但这似乎有点困难(我对NSTableView没问题,但是'setDoubleAction'对于NSImage不可用,并且有关NSImageView动作的答案(在此处或与Google一起使用)都指向制作一个NSButton而不是NSImageView,所以这样做无济于事.

I would now like to set an action for when user double click on these NSImageView, but it seems to be a little bit difficult (I had no trouble for NSTableView, but 'setDoubleAction' is not available for NSImage, and tons of answers (here or with google) concerning NSImageView's actions point to making a NSButton instead of NSImageView, so that doesn't help)

这是我AppDelegate.h的一部分:

Here is part of my AppDelegate.h:

@interface AppDelegate : NSObject <NSApplicationDelegate>{

    (...)

    @property (assign) IBOutlet NSImageView *iconeStatus;

    (...)

@end

这是我AppDelegate.m的一部分:

and here is part of my AppDelegate.m:

#import "AppDelegate.h"

@implementation AppDelegate

(...)

@synthesize iconeStatus = _iconeStatus;

(...)

- (void)awakeFromNib {

    (...)

[_iconeStatus setTarget:self];
[_iconeStatus setAction:@selector(doubleClick:)];

    (...)

}

(...)

- (void)doubleClick:(id)object {
        //make sound if that works ...
        [[NSSound soundNamed:@"Basso"] play];

}

但这不起作用.

谁能告诉我最简单的方法是什么?

Can anyone tell me what's the easiest way to do this ?

推荐答案

您需要对NSImageView进行子类化,并在子类的实现中添加以下方法:

You need to subclass NSImageView and add the following method to your subclass's implementation:

- (void)mouseDown:(NSEvent *)theEvent
{
    NSInteger clickCount = [theEvent clickCount];

    if (clickCount > 1) {
        // User at least double clicked in image view
    }
}

这篇关于NSImageView双击动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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