我有一个自定义 NSView 子类,它在我的项目https://github.com/torchie/TrackKit中用作子视图。它检测 NSTouch 并收集它们的物理数据,然后在其 drawRect 的详细模式方法中绘制这些东西。同时,SpriteKit 场景渲染它所渲染的内容。
但是,当我在内置触控板上移动手指时,SpriteKit 视图中的所有渲染都会暂停,直到触摸再次静止。在 Magic Trackpad 上,帧率下降,但渲染并未完全停止。在这两种情况下,子视图 TKDetectorView 都会继续渲染触摸点。
有问题的 touchesMoved 方法:
-(void)touchesMovedWithEvent:(NSEvent *)event {
for(NSTouch* touch in [event touchesMatchingPhase:NSTouchPhaseAny inView:self]) {
[touch_identities setObject:touch forKey:[touch identity]];
}
[self phys_record];
if(![self needsDisplay]) {
[self setNeedsDisplay:YES];
}
}
来自详细模式功能断点的数据,其中我同时触摸了内置触控板 (#0) 和 Magic Trackpad (#1):
touch_identities __NSDictionaryM * 2 key/value pairs 0x0000608000055bd0
[0] (null) (no summary) : (no summary)
key NSConcreteValue * 0x600000054b80 0x0000600000054b80
value NSTouch * 0x6000000b2480 0x00006000000b2480
NSObject NSObject
_index NSInteger 10 10
_identity NSConcreteValue * 0x600000054b80 0x0000600000054b80
_phase NSTouchPhase 2 2
_normalizedPosition NSPoint (x=0.4923553466796875, y=0.4602508544921875)
x CGFloat 0.4923553466796875 0.4923553466796875
y CGFloat 0.4602508544921875 0.4602508544921875
_privateFlags NSInteger 0 0
_view TKDetectorView * 0x6000001ff900 0x00006000001ff900
_device NSObject * 0x600000013300 0x0000600000013300
_deviceSize NSSize (width=368.50393709999997, height=311.81102370000002)
previous_positions NSMutableArray * nil 0x0000000000000000
_isResting BOOL YES '\xad'
[1] (null) (no summary) : (no summary)
key NSConcreteValue * 0x60800005ea50 0x000060800005ea50
value NSTouch * 0x6080000b3740 0x00006080000b3740
NSObject NSObject
_index NSInteger 1 1
_identity NSConcreteValue * 0x60800005ea50 0x000060800005ea50
_phase NSTouchPhase 2 2
_normalizedPosition NSPoint (x=0.7928314208984375, y=0.3984222412109375)
_privateFlags NSInteger 0 0
_view TKDetectorView * 0x6000001ff900 0x00006000001ff900
_device NSObject * 0x600000014d70 0x0000600000014d70
_deviceSize NSSize (width=297.63779534999998, height=215.43307092000001)
previous_positions NSMutableArray * nil 0x0000000000000000
_isResting BOOL YES '\xad'
我认为这可能是 SpriteKit 渲染线程被手指移动时位置数组的不断修改所中断的结果,但这并不能解释为什么它只发生在 MacBook Air 的内置触控板上和不是外部魔术触控板。我发现设备之间对 touchesMoved 的解释没有相关差异。