0

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)
    }
}
Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • I cannot replicated your issue. I've always a gray window changing `skHeight` also with 10.000. Tests maded with Xcode 9.4.1 and an iPhone SE. Could it related with a specific device? – Alessandro Ornano Aug 31 '18 at 07:57
  • 2048 is your limit because that is how large the frame buffer can be (actually it is 4096 but it is accounting for @2x retina). – Knight0fDragon Aug 31 '18 at 13:17
  • why would you want your view to be that large anyway, no device has a screen larger than that – Knight0fDragon Aug 31 '18 at 13:19
  • @Knight0fDragon thanks for the help! because the goal is to embed the SKView inside a UIScrollView. scrolling works great when the scene and SKView are < 2048, but it breaks when the SKView height is > 2048 because the SKView (and therefore the scene) no longer appears. also, some users like the first commenter report seeing the SKView with heights > 2048. – Crashalot Aug 31 '18 at 15:59
  • @AlessandroOrnano could you try testing against the iPhone or iPad on the simulator? thanks for the help! – Crashalot Aug 31 '18 at 16:00
  • OK, the system is not really designed for what you want, but to get around it, do not place your SKView in your UIScrollView, place a filler UIView into it, then pass the scroll position into your SKView and move your scene. If I had better context as to why you need a UIScrollView, I could maybe provide a better response – Knight0fDragon Aug 31 '18 at 16:03
  • @Knight0fDragon thanks again! this question was borne out of the original question (scrolling the SKView). we tried using the filler UIView, but two levels of scrolling occurred: once with the UIScrollView and the second when moving the scene. how do you get around this? – Crashalot Aug 31 '18 at 16:13
  • You dont put the skview inside of your scroll view lol – Knight0fDragon Aug 31 '18 at 16:13
  • @Knight0fDragon ugh, of course. :) so stupid! thanks! btw are you sure about the 2048 limitation? other users (like the first commenter) report seeing the SKView with heights > 2048. thanks again! – Crashalot Aug 31 '18 at 16:17
  • @Crashalot - first commenter said *"... always a gray window ..."* -- I don't think he ever saw the red subview. – DonMag Aug 31 '18 at 16:27
  • @DonMag the SKView is not actually red, setting `backgroundColor` on the SKView does nothing actually (should have been removed from question). the SKView is represented by the gray window. – Crashalot Aug 31 '18 at 16:30
  • @Crashalot, it is not an issue with Metal Rendering, only OpenGL – Knight0fDragon Sep 04 '18 at 18:08

1 Answers1

1

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)

Knight0fDragon
  • 16,609
  • 2
  • 23
  • 44