替换现有 NSView 的 NSResponder
我在绘图应用程序中有一个视图,当选择其他工具时,它需要以其他方式响应。我认为替换该视图的 NSResonder 会比设置视图的每个响应者方法调用新的响应者方法要好得多。这可能吗,还有其他好的解决方案吗?
I have a view in an drawing application, it needs to respond in an other way when an other tool is selected. I thought it would be much nicer to replace the NSResonder of that view in stead of setting every responder method of the view call the new responder method. Is this possible, of is there an other nice solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个
NSView
对象并不“拥有”一个NSResponder
。NSResponder
是NSView
继承的*超类,所以不,它不能更改。最简单的解决方案就是保留一个 ivar 来跟踪当前选择的工具,然后使用该 ivar 来确定在NSResponder
方法中采取什么操作(-mouseDown:
, ETC。)。Each
NSView
object does not "have" anNSResponder
.NSResponder
is the *superclass from whichNSView
inherits, so no, it can not be changed. The easiest solution would be just to keep an ivar that tracks which tool is currently selected, then use that ivar to determine what action to take in theNSResponder
methods (-mouseDown:
, etc.).