- [NSResponder swipeWithEvent:] not called

I am writing an application focused on OS X Lion and Snow Leopard. I have an opinion that I want to respond to napkin events. My understanding is that three finger clicks will call -[NSResponder swipeWithEvent:] if this method is implemented in my user view. I already examined this question and the corresponding answers and tried the following modified Oscar Del Ben code implementation:

 @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 

This compiles and works fine, and the view is displayed as expected. mouseDown: event mouseDown: correctly logged. 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 the project / application parameter somewhere in order to correctly receive and / or interpret gestures? Thank you in advance.

+7
source share
4 answers

To receive swipeWithEvent: messages, you must make sure that the three-finger trick is not tied to anything that could cause a conflict. Go to System Settings → Trackpad → Additional gestures and set these settings for one of the following:

  • Swipe between pages:

    • Swipe two or three fingers, or
    • Swipe three fingers.

  • Swipe between full-screen apps:

    • Swipe left or right with four fingers.

In particular, swipe between full-screen applications should not be three fingers, otherwise you will not receive a swipeWithEvent: message.

Together, these two preference parameters trigger the swipeWithEvent: messages that should be sent to the first responder.

Of course, you still have to implement the real swipe logic. And if you want to scroll with liquid, you will need to do a little work. The following is an example of how to do this in the Lion App Kit release notes in the Trace of Fluid section.

See http://developer.apple.com/library/mac/#releasenotes/Cocoa/AppKit.html

+9
source

try [self setAcceptsTouchEvents:YES]; where it says // Initialization code here.

+2
source

Not sure if this is a problem, but only the key window receives Gestures. Your window key?

+1
source

Is your opinion the acceptance of the first respondents?

 - (BOOL) acceptsFirstResponder { return YES; } 
0
source

All Articles