我正在编写一个针对OS X Lion和Snow Leopard的应用程序。我有一个观点,我想对滑动事件做出响应。我的理解是,如果在我的自定义视图中实现该方法,那么三指轻扫将会调用-[NSResponder swipeWithEvent:]
。我已经看过this问题和相应答案,并试图以下修改存根实现的奥斯卡德尔本的代码:- [NSResponder swipeWithEvent:] not called
@implementation TestView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
[[NSColor redColor] set];
NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
}
- (void)swipeWithEvent:(NSEvent *)event {
NSLog(@"Swipe event detected!");
}
- (void)beginGestureWithEvent:(NSEvent *)event {
NSLog(@"Gesture detected!");
}
- (void)endGestureWithEvent:(NSEvent *)event {
NSLog(@"Gesture end detected!");
}
- (void)mouseDown:(NSEvent *)theEvent {
NSLog(@"mouseDown event detected!");
}
@end
这编译并运行良好,并且视图呈现预期。 mouseDown:
事件已正确注册。但是,没有其他事件被触发。 begin/endGestureWithEvent:
方法,也不是swipeWithEvent:
方法。这让我想知道:我是否需要在某处设置项目/应用程序设置以正确接收和/或解释手势?先谢谢您的帮助。
作为一个侧面说明,就可以得到'滚动手势 - [NSResponder类滚轮:]',但我想专门使用三指手势 – nomothetis