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

后端 未结 1 1240
北恋
北恋 2021-02-08 00:21

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.

相关标签:
1条回答
  • 2021-02-08 00:35

    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).

    0 讨论(0)
提交回复
热议问题