我是Mac OS X开发的新手。是否可以创建一个应用程序,当用户long-presses
对Finder
中的文件名执行操作时。我不知道如何拦截long-press
......
答案 0 :(得分:0)
// ---------------------------------
- (BOOL)acceptsFirstResponder
{
return YES;
}
// ---------------------------------
- (BOOL)becomeFirstResponder
{
return YES;
}
// ---------------------------------
- (BOOL)resignFirstResponder
{
return YES;
}
// ---------------------------------
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
// Do some test to see if we should handle the mouse down and set an instance BOOL variable myMouseClick (that mouseUp can also see)
if(myMouseClick)
{
time = CFAbsoluteTimeGetCurrent () // time is also an instance variable mouseUp can see.
}
}
// ---------------------------------
- (void)mouseUp:(NSEvent *)theEvent
{
if (myMouseClick)
{
CFTimeInterval deltaTime = CFAbsoluteTimeGetCurrent () - time;
if(deltaTime > 2.0)
{
// Do your long click action
}
}
}