iOS Storyboard: Views outside of the ViewController and on Top of the Scene (between First Responder and Exit boxes)

久未见 提交于 2020-01-12 04:34:32

问题


I am having a hard time understanding why you can put UIViews outside the UIViewController on the storyboard, and what the use case of it might be.

For instance, on the storyboard I can add UIToolbar, UIAcitivtyIndicator and UIProgressView that is outside of the UIViewController. Is this mean there is a way for you to reference those Views that are outside UIViewController and potentially display them somehow either programmatically or embed those like you would do with a ContainerView?


回答1:


Yes, it absolutely is possible to do what you're describing!

When you add objects that are outside the view controller, they appear in what Apple calls the "Scene Dock". Apple has the following suggested usage for the scene dock:

If a view is not part of the main view hierarchy — such as a pop-up menu — add the view to the scene dock. In a running app, the system adds and removes these kind of views from the view hierarchy when they are opened and closed.

The steps to make this work are below:

  1. Open the storyboard.

  2. Open the utilities area for the workspace window by clicking the utilities button in the toolbar.

  3. In the utilities area, select the Object library by clicking the Object Library button in the library bar.

  4. On the storyboard, select the scene to which you will add the extra view.

  5. Drag a view class object from the object library into the the scene dock.

And importantly...

The added view is a part of the view controller. It will be instantiated along with the rest of the views. You can attach the view to a property of the view controller that has an IBOutlet. You can add more than one view to the scene dock.

(These steps were originally copied from here - unfortunately this page seems to have been deleted by Apple at some point).



来源:https://stackoverflow.com/questions/37954223/ios-storyboard-views-outside-of-the-viewcontroller-and-on-top-of-the-scene-bet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!