我正在编写一个针对OS、狮子和雪豹的应用程序。我有一个观点,我想要有反应的滑动事件。我的理解是,如果在我的自定义视图中实现了该方法,则三指滑动将调用-[NSResponder swipeWithEvent:]
。我已经查看了this问题和相应的答案,并尝试了Oscar Del Ben代码的以下修改存根实现:
@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:
方法。这让我想知道:我是否需要在某个地方设置一个项目/应用程序设置来正确地接收和/或解释手势?提前谢谢你的帮助。
发布于 2011-12-08 07:59:56
要接收swipeWithEvent:消息,您必须确保3指滑动手势不会映射到可能导致冲突的任何东西。转到-> Trackpad ->更多手势,并将这些首选项设置为以下之一:
1. Swipe with two or three fingers, or
2. Swipe with three fingers
1. Swipe left or right with four fingers
具体来说,全屏应用程序之间的滑动不应该设置为三个手指,否则您将不会收到swipeWithEvent:消息。
这两个首选项设置一起导致将swipeWithEvent:消息发送到第一个响应程序。
当然,您仍然需要实现实际的swipe逻辑。如果您想要执行流体滚动-滑动la iOS,那么您将需要做更多的工作。在Lion发布说明中,有一个例子说明了如何在“流体滑动跟踪”一节中这样做。
请参阅http://developer.apple.com/library/mac/#releasenotes/Cocoa/AppKit.html
发布于 2012-04-10 21:00:07
试着用[self setAcceptsTouchEvents:YES];
,上面写着// Initialization code here.
发布于 2011-09-15 22:11:12
不确定是否是问题所在,但只有键窗口接收手势。你的窗户钥匙吗?
https://stackoverflow.com/questions/7433120
复制相似问题