0

In reference to my previous question here:

Swift 2.0, SpriteKit - Scrollview to not use pages.

I am trying to get the scrollview (which is a subclass of UIScrollView) that I have to lock onto a sprite in the middle of the screen instead of just being able to stop the scrolling on the gap between the sprites.

I am also trying to get the sprite to slightly enlarge when it's in the center of the screen (like the crossy road character selection menu)

Here is my scrollview:

scrollView = CustomScrollView(frame: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height), scene: self, moveableNode: moveableNode, scrollDirection: .Horizontal)
    scrollView.contentSize = CGSizeMake(self.frame.size.width * 3, self.frame.size.height) // * 3 makes it three times as wide as screen
    view!.addSubview(scrollView)

    /// Set scrollView to first page
    scrollView.setContentOffset(CGPoint(x: 0 + self.frame.size.width * 2, y: 0), animated: true)

    /// ScrollView Sprites for each page in scrollView
    /// Makes positioning much easier.
    let page1ScrollView = SKSpriteNode(color: SKColor.clearColor(), size: CGSizeMake(self.frame.size.width, self.frame.size.height))
    page1ScrollView.zPosition = -1
    page1ScrollView.position = CGPointMake(CGRectGetMidX(self.frame) - (self.frame.size.width * 2), CGRectGetMidY(self.frame))
    moveableNode.addChild(page1ScrollView)

    let page2ScrollView = SKSpriteNode(color: SKColor.clearColor(), size: CGSizeMake(self.frame.size.width, self.frame.size.height))
    page2ScrollView.zPosition = -1
    page2ScrollView.position = CGPointMake(CGRectGetMidX(self.frame) - (self.frame.size.width), CGRectGetMidY(self.frame))
    moveableNode.addChild(page2ScrollView)

    let page3ScrollView = SKSpriteNode(color: SKColor.clearColor(), size: CGSizeMake(self.frame.size.width, self.frame.size.height))
    page3ScrollView.zPosition = -1
    page3ScrollView.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
    moveableNode.addChild(page3ScrollView)


    /// Test label page 1
    let sprite1 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
    sprite1.position = CGPointMake(0, 0)
    page1ScrollView.addChild(sprite1)

    let sprite2 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
    sprite2.position = CGPointMake(sprite1.position.x + (sprite2.size.width * 1.5), sprite1.position.y)
    sprite1.addChild(sprite2)

    let sprite3 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
    sprite3.position = CGPointMake(sprite2.position.x + (sprite3.size.width * 1.5), sprite1.position.y)
    sprite1.addChild(sprite3)

I have tried implementing the locking code found in ray's project (refer to link question) but I have had no luck getting it to work. Any ideas?

Community
  • 1
  • 1
Astrum
  • 375
  • 6
  • 21
  • I tried posting an answer but it didnt work so I deleted it. I will play around with my scrollView and see if I can make it work. In the meantime you can try this and see if it fullfils your needs. https://github.com/burczyk/SwiftTeamSelect – crashoverride777 Feb 07 '16 at 14:14
  • @crashoverride777 did you ever get around to achieving this? because I couldn't and still can't figure it out I have a more up to date question if you have time please help. http://stackoverflow.com/questions/38734589/scrollview-stopping-at-a-certain-point/38736814?noredirect=1#comment64856198_38736814 – Astrum Aug 03 '16 at 10:48
  • Hey. Sorry I don't. I am not really using this helper anymore (I am still updating it tho), I prefer to use UICollectionViews. I don't do the enlarging like you want to so not sure what to do. Why don't you use the project I posted in my last answer? Its on Github and is written in swift and for SpriteKit and seems to do exactly what you want. https://github.com/burczyk/SwiftTeamSelect. – crashoverride777 Aug 03 '16 at 17:31

0 Answers0