我的 NSImageView 未检测到 mouseDown
我一直在寻找这个问题的答案,虽然我已经完成了这些步骤,但我似乎仍然无法调用 mouseDown 方法。 我想要的是当用户单击并按住图像时,它应该打印出“鼠标按下!”。 (最终我想做的是用户单击并按住图像以播放声音,当他们松开时声音就会停止)。
这就是我所拥有的。我的标题:
@interface MyNSImageView : NSImageView <NSImageDelegate> {
}
@end
我的班级:
@implementation MyNSImageView
- (void)mouseDown:(NSEvent *)event {
if ([[self target] respondsToSelector:[self action]]) {
[NSApp sendAction:[self action] to:[self target] from:self];
}
NSLog(@"Mouse Down!");
}
@end
这看起来正确吗?如果是这样,那么是否还有其他问题可能会干扰它?不然我该怎么办?
多谢多谢!
I've been searching for answers to this question and while I have done the steps I still cannot seem to get the mouseDown method to be called.
What I want is when the user clicks and holds down on the image, it should print out "Mouse down!".
(Eventually what I want to do is the user to click and hold on the image to cause a sound to play, and when they let go the sound will stop).
Here's what I have. My header:
@interface MyNSImageView : NSImageView <NSImageDelegate> {
}
@end
And my class:
@implementation MyNSImageView
- (void)mouseDown:(NSEvent *)event {
if ([[self target] respondsToSelector:[self action]]) {
[NSApp sendAction:[self action] to:[self target] from:self];
}
NSLog(@"Mouse Down!");
}
@end
Does this look right? If so, then are there other problems which might be interfering with it? Of not, what should I do?
Thanks heaps!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我的解决方案:
在 NSImageView 上方添加一个没有边框或标题的不可见按钮。
:)
Here's my solution:
Add an invisible button without border or title above the NSImageView.
:)
第一个想法:尝试实现
acceptsFirstResponder
并返回 yes。然后让你的委托将第一响应者设置为图像视图...更新:
所以,我刚刚创建了一个新项目,并向其中添加了一个类 MyClass,它继承自 NSImageView。 mouseDown 的实现:
和 initWithFrame 的实现:
使视图可见。
然后,我通过向窗口添加自定义类并将自定义类的类更改为 MyClass 来编辑 nib 文件。它工作得很好,所以我不知道出了什么问题。
First thought: Try implementing
acceptsFirstResponder
and return yes. Then have your delegate set the first responder to the image view....UPDATE:
So, I just created a new project, and added a class MyClass to it, which inherits from NSImageView. mouseDown is implemented:
and initWithFrame is implemented:
To make the view visible.
I then edited the nib file by adding a custom class to the window, and changing the class of the custom class to MyClass. It worked fine, so I dunno whats wrong.