开发者

Replace the NSResponder of an existing NSView

开发者 https://www.devze.com 2023-02-10 03:23 出处:网络
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 t开发者_如何学Gohe NSResonder of that view in s

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 t开发者_如何学Gohe 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?


Each NSView object does not "have" an NSResponder. NSResponder is the *superclass from which NSView 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 the NSResponder methods (-mouseDown:, etc.).

0

精彩评论

暂无评论...
验证码 换一张
取 消