Scrolling a SwiftUI Sprite View

SwiftUI provides a sprite view to show a SpriteKit scene in a SwiftUI app. Supply a SpriteKit scene to the sprite view.

SwiftUI provides a scroll view to scroll content that won’t fit in the main SwiftUI view. Place the sprite view inside the scroll view to scroll the scene.

If you build and run this code, you will notice the scroll view covers the sprite view so you can’t see the sprite view or interact with it. How do you keep the scroll view from blocking the sprite view?

Add a .frame modifier to the sprite view.

If you want to scroll the scene horizontally and vertically, supply the scrolling directions in an array when creating the scroll view.