开发者

How to implement the two-finger swipe gesture in Cocoa to go back and forward?

Several applications like Safari and the Finder go back and forward when you swipe with tw开发者_开发百科o fingers on your Magic Mouse (or with three fingers on your Magic Trackpad).

How would I implement this in my Cocoa application? What classes are available?


Three finger swipes are easiest, because NSResponder already does the work for you:

- (void)swipeWithEvent:(NSEvent *)event;

If you want to support two finger swipes (which I don't think technically can be classified as swipes, but rather scroll gestures), you'll have to manually process the touches- see http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/HandlingTouchEvents/HandlingTouchEvents.html#//apple_ref/doc/uid/10000060i-CH13-SW10


For me two-finger swipe worked with the Trackpad by subclassing the NSView descendant holding the info to be swiped (e.g. a NSScrollView instance) and then to implement -(void)scrollWheel:(NSEvent *)event. This method will be invoked for two-finger swipes, the direction of the swipe can be taken from the [event deltaX] and [event deltaY] properties.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜