简体   繁体   中英

Callback when NSView is added to NSWindow

Problem:

I am given a NSView from a third party library. When I am given the NSView it is not yet added to a NSWindow. I need to wait until the third party library adds the NSView to a NSWindow before executing some of my code. There is no method for the third party library to notify me when this happens. I need to check for this condition myself and I need the solution to work on OSX 10.9/10.10/10.11.

What I Tried:

  1. KVO on the "window" property in NSView. Works great but unfortunately the "window" property in NSView is not KVO compliant in OSX 10.9.

  2. Spawn a thread and periodically check whether the "window" property on the NSView != nil. Unfortunately leads to some slight delay.

Question:

Are there any KVO alternatives I can use for pre 10.10? Or any other solutions at all?

不好的方法是创建一个NSTimer来注意将视图添加到窗口中

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM