title: Zoom SKSpriteNode in AND out in Swift
body: <p>First off, I have already seen and tried to implement the other answers to similar questions <a href="https://stackoverflow.com/questions/21847063/zoom-and-scroll-sknode-in-spritekit">here</a>, <a href="https://stackoverflow.com/questions/21900614/sknode-scale-from-the-touched-point?lq=1">here</a> and <a href="https://stackoverflow.com/questions/19082251/zooming-and-scrolling-in-spritekit?rq=1">here</a>. The problem is I started programming for iOS last year with Swift and (regrettably) I did not learn ObjC first (yes, it's now on my to-do list).  ;-)</p>
  
  <p>So please take a look and see if you might help me see my way thru this. </p>
  
  <p>I can easily pinch to zoom the whole SKScene. I can also scale an SKSpiteNode up/down by using other UI Gestures (ie. swipes) and SKActions. </p>
  
  <p>Based off <a href="https://stackoverflow.com/questions/19922792/center-skspritenode-during-pinch"> this post</a> I have applied the SKAction to the UIPinchGestureRecognizer and it works perfectly to zoom IN, but I cannot get it to zoom back OUT.</p>
  
  <p>What am I missing?</p>
  
  <p>Here is my code on a sample project:</p>
  
  <pre><code>class GameScene: SKScene {
  
  var board = SKSpriteNode(color: SKColor.yellowColor(), size: CGSizeMake(200, 200))
  
  func pinched(sender:UIPinchGestureRecognizer){
      println("pinched \(sender)")
      // the line below scales the entire scene
      //sender.view!.transform = CGAffineTransformScale(sender.view!.transform, sender.scale, sender.scale)
      sender.scale = 1.01
  
      // line below scales just the SKSpriteNode
      // But it has no effect unless I increase the scaling to &gt;1
      var zoomBoard = SKAction.scaleBy(sender.scale, duration: 0)
      board.runAction(zoomBoard)
  }
  
  // line below scales just the SKSpriteNode
  func swipedUp(sender:UISwipeGestureRecognizer){
      println("swiped up")
      var zoomBoard = SKAction.scaleBy(1.1, duration: 0)
      board.runAction(zoomBoard)
  }
  
  // I thought perhaps the line below would scale down the SKSpriteNode
  // But it has no effect at all
  func swipedDown(sender:UISwipeGestureRecognizer){
      println("swiped down")
      var zoomBoard = SKAction.scaleBy(0.9, duration: 0)
      board.runAction(zoomBoard)
  }
  
  override func didMoveToView(view: SKView) {
  
      self.addChild(board)
  
      let pinch:UIPinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: Selector("pinched:"))
      view.addGestureRecognizer(pinch)
  
  
      let swipeUp:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedUp:"))
      swipeUp.direction = .Up
      view.addGestureRecognizer(swipeUp)
  
      let swipeDown:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedDown:"))
      swipeDown.direction = .Down
      view.addGestureRecognizer(swipeDown)
  
  
  }
  
  override func touchesBegan(touches: Set&lt;NSObject&gt;, withEvent event: UIEvent) {
      // should I be using this function instead?
  
  
  }
  </code></pre>
  
  <p>Thanks to the help from @sangony I have gotten this working finally. I thought I'd post the working code in case anyone else would like to see it in Swift.</p>
  
  <pre><code>var board = SKSpriteNode(color: SKColor.yellowColor(), size: CGSizeMake(200, 200))
  
  var previousScale = CGFloat(1.0)
  
  func pinched(sender:UIPinchGestureRecognizer){
      if sender.scale &gt; previousScale {
          previousScale = sender.scale
          if(board.size.height &lt; 800) {
              var zoomIn = SKAction.scaleBy(1.05, duration:0)
              board.runAction(zoomIn)
          }
      }
      if sender.scale &lt; previousScale {
          previousScale = sender.scale
          if(board.size.height &gt; 200) {
              var zoomOut = SKAction.scaleBy(0.95, duration:0)
              board.runAction(zoomOut)
          }
      }
  </code></pre>