-[NSResponder swipeWithEvent:]未调用 [英] -[NSResponder swipeWithEvent:] not called

查看:79
本文介绍了-[NSResponder swipeWithEvent:]未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个针对OS X Lion和Snow Leopard的应用程序。我认为我想对滑动事件做出回应。我的理解是,如果在我的自定义视图中实现了该方法,则三指滑动会调用-[NSResponder swipeWithEvent:] 。我已经查看过这个问题和相应的答案,并尝试了以下修改奥斯卡·德尔·本的代码的存根实现:

I am writing an application targeting OS X Lion and Snow Leopard. I have a view that I want to have respond to swipe events. My understanding is that three-finger swipes will call -[NSResponder swipeWithEvent:] if that method is implemented in my custom view. I have already looked at this question and corresponding answers, and tried the following modified stub implementation of Oscar Del Ben's code:

@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:方法都没有。这让我感到奇怪:是否需要在某个地方设置项目/应用程序设置才能正确接收和/或解释手势?在此先感谢您的帮助。

This compiles and runs fine, and the view renders as expected. The mouseDown: event is properly registered. However, none of the other events are triggered. Neither the begin/endGestureWithEvent: methods, nor the swipeWithEvent: method. Which makes me wonder: do I need to set a project/application setting somewhere to properly receive and/or interpret gestures? Thanks in advance for the help.

推荐答案

要接收 swipeWithEvent:消息,您必须确保三指滑动手势未映射到任何可能引起冲突的内容。转到系统偏好设置->触控板->更多手势,并将这些偏好设置设置为以下选项之一:

To receive swipeWithEvent: messages, you have to ensure that the 3 finger swipe gesture is not mapped to anything that might cause a conflict. Go to System preferences -> Trackpad -> More Gestures, and set these preferences to one of the following:


  • 在页面之间滑动:

  • Swipe between pages:


  1. 用两三个手指滑动,或

  2. 用三个手指滑动



  • 在全屏应用程序之间滑动:

  • Swipe between full-screen apps:


  1. 用四根手指向左或向右滑动


特别是,全屏应用之间的滑动不应设置为三个手指,否则您将不会获得 swipeWithEvent:消息。

Specifically, the swipe between full-screen apps should not be set to three fingers, otherwise you will not get swipeWithEvent: messages.

这两个首选项设置一起将 swipeWithEvent:消息发送给第一响应者。

Together, these two preference settings cause swipeWithEvent: messages to be sent to the first responder.

当然,您仍然必须实现实际的滑动逻辑。而且,如果您想在iOS上执行流畅的滚动滑动,则需要做更多的工作。 Lion App Kit发行说明中的​​流体刷卡跟踪部分提供了一个示例。

Of course, you still have to implement the actual swipe logic. And if you want to perform a fluid scroll-swipe à la iOS, then you will need to do a little more work. There is an example of how to do this in the Lion App Kit release notes under the section "Fluid Swipe Tracking."

请参见http://developer.apple.com/library/mac/#releasenotes/Cocoa/AppKit.html

这篇关于-[NSResponder swipeWithEvent:]未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆