NSTextField over NSOpenGLView

前端 未结 7 2081
情歌与酒
情歌与酒 2021-02-08 05:42

I have made a window with an NSOpenGLView that I am rendering openGL content into.

I want to add some buttons and text fields to the view: I can add NSTextFields and NSB

7条回答
  •  南旧
    南旧 (楼主)
    2021-02-08 05:52

    1) The NSOpenGLView can have a subview. It can have plenty even.

    2) The reason some views, controls and other elements are being bullied by NSOpenGLView is due to the loading process when the Application launches. I.e If you add a slider or textfield above and into the content view of the window where the NSOpenGLView also resides, upon Application-Launch that textfield will most likely wind up beneath the NSOpenGLView.

    This is an Apple Bug. And they know about it.

    You can solve it quite easily even without adding a subview to NSOpenGLView...

    In Interface Builder drag i.e. a CustomView into the canvas (Not the view). And set it the way you want it with sliders, text and what not. Then create an outlet (Call it i.e topView) in your view controller. Then somewhere in your code... Perhaps (applicationDidFinishLaunching) add this line...

    [_window.contentView addSubview:_topView]; (Do your positioning & layout) This will do the exact same thing as if you had dragged it into the contentView yourself inside IB. Only it will draw the darn thing in the correct Z position.

    You loose IB's constraints this way and have to it manually

    One could also just subclass and CAOpenGLLayer and use that as a backing layer inside of a regular NSView. There too it is drawn correctly...

    Here is Apple's way of wanting to do that. CALayers are a Godsend ;)

    Enter following String ** NSOpenGLLayer** in search and hit enter to get to where it is... NSOpenGLLayer

    Hope this helps....

提交回复
热议问题