在我的应用程序中,我希望滚动发生,只有通过鼠标的滚轮动作,而不是通过触控板上的两个手指手势。基本上,我正在尝试确定scrollWheelEvent是从鼠标还是触控板生成的,在- (void)scrollWheel:(NSEvent *)theEvent方法中。到目前为止,据我所知,似乎没有简单的方法来实现这一点。
我尝试过在-(void)beginGestureWithEvent:(NSEvent *)事件和-(void) endGestureWithEvent:(NSEvent *)事件内部将布尔变量设置为true和false;但这不是一个解决方案,因为在调用endGestureWithEvent:方法之后,scrollWheel:方法会被多次调用。
下面是我的代码:
$BOOL fromTrackPad = NO;
-(void)beginGestureWithEvent:(NSEvent *)event;
{
fromTrackPad = YES;
}
-(void) endGestureWithEvent:(NSEvent *)event;
{
fromTrackPad = NO;
}
- (void)scrollWheel:(NSEvent *)theEvent
{
if(!fromTrackPad)
{
//then do scrolling
}
else
{
//then don't scroll
}
}
我知道这不是标准的东西,但这是我的要求。有人知道怎么做吗??谢谢!
发布于 2012-12-21 06:27:59
-[NSEvent momentumPhase]
是解决方案。因此,在beginGesture和endGesture事件之间从触控板生成的事件返回的值不是NSEventPhaseNone
(对于-[NSEvent phase]
),而在endGesture事件之后生成的触控板事件返回的值不是NSEventPhaseNone
(对于-[NSEvent momentumPhase]
)。代码如下:
- (void)scrollWheel:(NSEvent *)theEvent
{
if(([theEvent momentumPhase] != NSEventPhaseNone) || [theEvent phase] != NSEventPhaseNone))
{
//theEvent is from trackpad
}
else
{
//theEvent is from mouse
}
}
https://stackoverflow.com/questions/13807616
复制相似问题