子类化NSSlider:需要一种变通方法来解决缺少鼠标上移事件(Cocoa OSX) [英] Subclassing NSSlider: Need a workaround for missing mouse up events (Cocoa OSX)

查看:151
本文介绍了子类化NSSlider:需要一种变通方法来解决缺少鼠标上移事件(Cocoa OSX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将NSSlider子类化,以创建一个称为慢速拨盘的控件.基本上,我需要一个始终从中间开始的滑块,当它向左或向右移动时,它会每隔一段时间(由一个可以设置的属性确定)发送通知,以通知其容器其当前值,然后当您让您松开旋钮,它将回到中间.我希望实现将滑块返回到中间并停止在滑块的mouseUp事件中发送通知的功能,但似乎出于某种原因,苹果在滑块上的mouseDown事件之后禁用了MouseUp事件并处理了所有滑块功能在较低的水平.无论如何,我可以找回mouseUp事件吗?如果没有人可以建议一个合理的解决方法?

I am trying to subclass NSSlider to create a control called a jog dial. Basically what I need is a slider which always starts at the middle and when it is moved to the left or right it will send notifications every so often (determined by an attribute one can set) informing its container of its current value, then when you let you go of the knob, it will return to the middle. I was hoping to implement the functionality to return the slider to the middle and stop sending notifications in the mouseUp event of the slider but it seems that for some reason apple disables the MouseUp event after a mouseDown event on the slider and handles all the slider functionality at a lower level. Is there anyway I can get the mouseUp event back? If not can anyone suggest a reasonable workaround?

推荐答案

每当您注意到未调用超类的mouseDragged:mouseUp:的实现时,最有可能是因为该类的mouseDown:的实现进入了跟踪循环.对于许多NSControl子类,包括NSSlider,当然都是如此.

Whenever you notice that a superclass's implementation of mouseDragged: or mouseUp: is not getting called, it's most likely because the class's implementation of mouseDown: enters a tracking loop. This is certainly true of many NSControl subclasses including NSSlider.

检测鼠标向上的更好方法是对单元格进行子类化,并覆盖适当的跟踪方法.在这种情况下,您可能需要- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag,但是startTracking:continueTracking:变体也可能对您尝试做的事情有用.

A better way to detect a mouse up is to subclass the cell and override the appropriate tracking method. In this case, you probably want - (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag, but the startTracking: and continueTracking: variants might prove useful as well for what you're trying to do.

这篇关于子类化NSSlider:需要一种变通方法来解决缺少鼠标上移事件(Cocoa OSX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆