0

I have a UINavigationBar that I placed within a UIViewController in the StoryBoard and created an IBOutlet for it in the viewController file. I am presenting an SKScene within the viewController and I want to access the navigation bar within the SKScene to get its height. Is there a way I can access the navigation bar within the SKScene?

I would have thought the "window" view would show the navigationBar as a subview, but it doesn't.

Any ideas?

malena
  • 798
  • 11
  • 26

1 Answers1

0

As pointed out in this thread:

How to reference a view controller from a view

You should not be referencing a view controller from a view. It is easy to get the view with

mySkscene.view

which returns the skview that is presenting your scene. From there, as indicated in the thread, you can pass the view controller as a delegate (which you create).

My suggestion is to create an IBOutlet for the navigation bar and pass the height to your skscene. Even better, create a particular view in your storyboard that uses the topLayoutBar for sizing, then use that view to present your scene. Make sure you get the size of that view in viewDidLayoutSubviews method of your viewController.

Community
  • 1
  • 1
Daniel K
  • 1,119
  • 10
  • 20