Zooming and scrolling in SpriteKit

Here is my solution to the scrolling problem. It revolves around “stealing” the behaviour from the UIScrollView. I learned this from a WWDC Video from 2012 about mixing UIKit with OpenGL.

  1. Add the UIScrollViewDelegate methods to your ViewController and set the scroll view delegate to the ViewController
  2. Add/Move the PanGestureRecognizer from the UIScrollView to the SKView
  3. Use the scrollViewDidScroll callback-method to control whatever node your want when the user scrolls

Example project:
https://github.com/bobmoff/ScrollKit

Like I mentioned in a comment above, I am experiencing some tiny lag about 30% of the times I am running the app. The FPS is still 60 but there seem to be some slight conflict or something with how often the delegate method is called, as it sometimes feel a little laggy. If anyone manages to solve this issue, I would love to hear about it. It seems to be only when I am holding my finger down, it never lags when the deceleration is happening.

Leave a Comment