我正在尝试使用触控板手势和普通鼠标事件将工作的IOS应用程序推广到Mac OSX。
简单的鼠标按下和鼠标拖动工作正常,但更相关的scrollWheel和触控板手势无法执行。
从IOS我知道我的场景需要为手势识别器声明一个委托协议,但在OSX上,这不应该是正常的NSReceiver行为吗?
我确实尝试了所有旧提示,包括使用触控板的系统偏好设置,到目前为止还没有成功。
如果有人知道触控板的Xcode示例项目,那么链接也会很棒。
#if TARGET_OS_IPHONE
@interface MAJMainScene() <UIGestureRecognizerDelegate>
#else
@interface MAJMainScene()
#endif
#if TARGET_OS_IPHONE
...
#else
#pragma mark OSX Event Handling
- (void)mouseDown:(NSEvent *)theEvent {
NSLog(@"mouseDown"); //this method is called
}
- (BOOL)acceptsFirstResponder {
return YES; // debug breakpoint never gets called
}
//reading apples documentation, the following method shouldn't be necessary for high-level trackpad gestures, I tried anyway.
- (BOOL)setAcceptsTouchEvents {
return YES; // debug breakpoint never gets called
}
- (void)scrollWheel:(NSEvent *)theEvent{
NSLog(@"Scroll"); //this method is NOT called
}
- (void)magnifyWithEvent:(NSEvent *)event {
NSLog (@"Magnification value is %f", [event magnification]); //NOT called
}
- (void)rotateWithEvent:(NSEvent *)event {
NSLog(@"rotate"); //NOT called
}
- (void)swipeWithEvent:(NSEvent *)event {
NSLog(@"swipe"); //NOT called
}
答案 0 :(得分:0)
我刚刚在Detect scroll wheel movement and direction
回答了类似的问题在您的情况下,您可以将所有其他事件转发到您的场景,如下所示:
@implementation SKView(ScrollTouchForwarding)
- (void)scrollWheel:(NSEvent *)event {
[self.scene scrollWheel:event];
}
- (void)magnifyWithEvent:(NSEvent *)event {
[self.scene magnifyWithEvent:event];
}
- (void)rotateWithEvent:(NSEvent *)event {
[self.scene rotateWithEvent:event];
}
- (void)swipeWithEvent:(NSEvent *)event {
[self.scene swipeWithEvent:event];
}
@end