0
votes

I am new to programming and am developing an iOS game. I have used only one view controller, which initializes the home SKScene and isn't used at all after that, and have around 6 SKScenes that can navigate between each other with the following code (in their respective scenes)

SKScene *storeScene = [[SKSceneStore alloc] initWithSize:self.size];
SKTransition *reveal = [SKTransition fadeWithDuration:0.5];
[self.view presentScene:storeScene transition:reveal];

One of my scenes is a store, and I would like to use scroll-kit (basically customizing code I found here ) to scroll through objects on my store.

In the github link above, which implements sprite-kit with UIScrollView, I have tried to move the UIScrollView code to the store SKScene but the

 - (void)scrollViewDidScroll:(UIScrollView *)scrollView

doesn't get called in sprite-kit scene. (I am trying to combine these into the store SKScene because my SKScenes have nothing to do with my view controller, and I feel like it would be messy keeping track of the SKScene and whether or not the UIScrollView exists in the View Controller).

So my question: How can I get

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

to fire off if it is in SKScene rather than UIViewController?

2

2 Answers

1
votes

To do so, make use of NSNotificationCenter

1: In viewDidLoad() add this

NSNotificationCenter.defaultCenter().addObserver(self, selector: "Facebook", name: "FacebookShare", object: nil)

2: In the method whereby you want to pass a function from UIViewController toSKScene

NSNotificationCenter.defaultCenter().postNotificationName("FacebookShare", object: nil)
0
votes

Yes you can. Use the view in -(void)willMoveFromView:(SKView *)view. That is the same as using it in the view controller.