iosuiviewsprite-kitsksceneskview

SpriteKit: why does SKView disappear at one height but appears at another height? What's the maximum height for SKView?


The code below shows a SKView until you change skHeight to 2050 or some higher value like 5000.

1) How can you make the SKView appear even at heights of 2050 or 5000?

2) What's the maximum size for SKViews?

To reproduce:

1) Run the code below. You will see the SKView represented as a gray window.

2) Change skHeight to 2050 or 5000. The SKView no longer appears.

class TestViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        // Create SKView
        let skHeight = CGFloat(2050)
        let skFrame = CGRect(x: 0, y: 0, width: 100, height: skHeight)
        let skView = SKView(frame: skFrame)
        skView.backgroundColor = UIColor.red

        // Add test view to <scrollView>
        view.addSubview(skView)
    }
}

Solution

  • OpenGL rendering does not support canvas sizes greater than 4096x4096 on many devices, your view is 2050x2050, so when you factor in retina mode, it really becomes 4100x4100.

    Now the @3x devices are even crazier, because it needs to handle the hardware scaling and shrinking, so you only end up getting views of about 1501x1501.

    Metal does not have this problem, and as of iOS 12, OpenGL is deprecated, so hopefully the Simulators will be using Metal as well. (It should since Mojave only supports metal devices)