如何在Cocoa中实现两指滑动手势来后退和前进?
当您在 Magic Mouse 上用两根手指轻扫时,Safari 和 Finder 等多种应用程序会后退和前进(或用三个手指放在妙控板上)。
我将如何在我的 Cocoa 应用程序中实现这一点?有哪些课程可供选择?
Several applications like Safari and the Finder go back and forward when you swipe with two 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
三指滑动是最简单的,因为 NSResponder 已经为您完成了这项工作:
如果您想支持两根手指滑动(我认为从技术上讲这不能归类为滑动,而是滚动手势),您必须手动处理触摸-参见http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/HandlingTouchEvents/HandlingTouchEvents.html#//apple_ref/doc/uid/10000060i-CH13-SW10
Three finger swipes are easiest, because NSResponder already does the work for you:
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
对我来说,两指滑动与触控板配合使用,方法是对保存要滑动信息的 NSView 后代进行子类化(例如 NSScrollView 实例),然后实现 -(void)scrollWheel:(NSEvent *) 事件。对于两指滑动将调用此方法,滑动方向可以从 [event deltaX] 和 [event deltaY] 属性中获取。
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.