小编nom*_*tis的帖子

- [NSResponder swipeWithEvent:]未调用

我正在编写一个针对OS X Lion和Snow Leopard的应用程序.我有一个观点,我想要回应滑动事件.我的理解是,-[NSResponder swipeWithEvent:]如果在我的自定义视图中实现了该方法,则三指滑动将调用.我已经看过这个问题和相应的答案,并尝试了以下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
Run Code Online (Sandbox Code Playgroud)

这编译并运行正常,视图按预期呈现.该mouseDown:事件已正确注册.但是,没有其他事件被触发.既不是begin/endGestureWithEvent:方法,也不是swipeWithEvent: …

cocoa gestures swipe osx-lion

7
推荐指数
1
解决办法
3817
查看次数

标签 统计

cocoa ×1

gestures ×1

osx-lion ×1

swipe ×1