我正在尝试对我放在背景视图中的视图实施鼠标拖动支持。但是当我拖动控件时,鼠标指针似乎比我正在拖动的视图“更快”。我在每个<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="box" style="width:100px;">Nothing to say</div>
事件中使用deltaX值来移动视图。将所有mouseDragged:
值的总和与初始值NSEvent.deltaX
之间的差值进行比较时,会产生差异(.locationInWindow.x
和总是小于实际的X差值)。看起来我正以某种方式“失去”deltaX
事件。
mouseDragged:
结果:
- (void) mouseDown:(NSEvent *)theEvent {
[super mouseDown:theEvent];
// - irrelevant code removed
clickPos = theEvent.locationInWindow;
sumDeltaX = 0.0;
}
- (void) mouseDragged:(NSEvent *)theEvent {
[super mouseDragged:theEvent];
// -irrelevant code removed
sumDeltaX += theEvent.deltaX;
NSLog(@"Drag: diff. start/current=%.0f ; sum of deltaX=%.0f", theEvent.locationInWindow.x-clickPos.x, sumDeltaX);
}
当我慢慢拖动时效果更明显(=生成更多事件?);当我快速拖动时,我几乎没有失去任何东西。
2015-05-19 13:52:48.927 MSB Playout 2[1124:497022] Drag: diff. start/current=2 ; sum of deltaX=2
2015-05-19 13:52:48.944 MSB Playout 2[1124:497022] Drag: diff. start/current=3 ; sum of deltaX=3
2015-05-19 13:52:48.961 MSB Playout 2[1124:497022] Drag: diff. start/current=6 ; sum of deltaX=5
2015-05-19 13:52:48.978 MSB Playout 2[1124:497022] Drag: diff. start/current=9 ; sum of deltaX=7
2015-05-19 13:52:48.995 MSB Playout 2[1124:497022] Drag: diff. start/current=12 ; sum of deltaX=10
2015-05-19 13:52:49.012 MSB Playout 2[1124:497022] Drag: diff. start/current=17 ; sum of deltaX=14
和mouseDown
位置之间的差异是可能的,但对我来说看起来并不优雅。所有建议都赞赏!