gpt4 book ai didi

cocoa - -[NSResponder swipeWithEvent :] not called

转载 作者:行者123 更新时间:2023-12-03 16:07:05 25 4
gpt4 key购买 nike

我正在编写一个针对 OS X Lion 和 Snow Leopard 的应用程序。我有一个观点,我想响应滑动事件。我的理解是,如果在我的自定义 View 中实现了该方法,三指滑动将调用 -[NSResponder swipeWithEvent:] 。我已经看过this问题和相应的答案,并尝试了 Oscar Del Ben 代码的以下修改 stub 实现:

@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

它编译并运行良好,并且 View 按预期呈现。 mouseDown: 事件已正确注册。但是,没有触发任何其他事件。既不是 begin/endGestureWithEvent: 方法,也不是 swipeWithEvent: 方法。这让我想知道:我是否需要在某处设置项目/应用程序设置才能正确接收和/或解释手势?预先感谢您的帮助。

最佳答案

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

  • 在页面之间滑动:

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

  • 在全屏应用之间滑动:

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

具体来说,全屏应用之间的滑动不应设置为三指,否则您将不会收到 swipeWithEvent: 消息。

这两个首选项设置共同导致 swipeWithEvent: 消息发送到第一响应者。

当然,您仍然需要实现实际的滑动逻辑。如果您想像 iOS 那样执行流畅的滚动滑动,那么您将需要做更多的工作。 Lion App Kit 发行说明中的​​“流畅滑动跟踪”部分提供了如何执行此操作的示例。

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

关于cocoa - -[NSResponder swipeWithEvent :] not called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7433120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com