单击鼠标时可可检测对象

时间:2014-08-09 02:39:17

标签: objective-c cocoa object nsimage nsevent

我创建了一个自定义对象(NSImageView)来显示图像,我使用addSubview:self.view来添加 我想确定鼠标是否单击它。 我该怎么办?

谢谢。

NSImage *Image = [NSImage imageNamed:@"oneimage.jpg"];
NSImageView *ImageView = [[NSImageView alloc] init];
[ImageView setImage:Image];
[self.window addSubview:ImageView];
[ImageView_IconToAdd setAcceptsTouchEvents:YES];
[ImageView_IconToAdd setWantsRestingTouches:YES];


-(void)mouseDragged:(NSEvent *)theEvent {
    id clickedObject = [self hitTest:[theEvent locationInWindow]];
    if ([clickedObject isKindOfClass:[NSImageView class]]) {
        NSLog(@"Clicked an ImageView");
    } else if ([clickedObject isKindOfClass:[NSView class]]) {
        NSLog(@"Clicked a WebView");
    }
}

但错误:

No visible @interface for 'WindowImage' declares the selector 'hitTest:'

并且无法获得对象!

0 个答案:

没有答案