- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个针对 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 指滑动手势未映射到任何可能导致冲突的内容。转到“系统偏好设置”->“触控板”->“更多手势”,并将这些偏好设置设置为以下选项之一:
在页面之间滑动:
在全屏应用之间滑动:
具体来说,全屏应用之间的滑动不应设置为三指,否则您将不会收到 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/
我正在编写一个针对 OS X Lion 和 Snow Leopard 的应用程序。我有一个观点,我想响应滑动事件。我的理解是,如果在我的自定义 View 中实现了该方法,三指滑动将调用 -[NSRes
在雪豹中有一个用于滑动事件的手势识别器: - (void)swipeWithEvent:(NSEvent *)event { CGFloat x = [event deltaX]; i
我正在编写一个简单的 cocoa 程序,应该使用滑动手势。我已经在我的 NSView 子类中实现了 swipeWithEvent: 方法,但是当我尝试该程序时,该方法从未被调用。 rotateWith
我想通过使用 Event swipeWithEvent 在我的 webView 中实现向后和第四导航的能力。但是,我不知道我应该如何使用它。 我有一个主 webView,以及两个向后导航和第四个导航的
我是一名优秀的程序员,十分优秀!