     }
     return numberOfBricks == 0
   }
-  
 }
 
 class StartScene: SKScene {
-  
+
   var contentCreated = false
 
   override func didMoveToView(view: SKView) {

    startNode.fontSize = 20
    startNode.position = CGPoint(x: CGRectGetMidX(frame), y: CGRectGetMidY(frame))
    startNode.name = "start"
    
    return startNode
  }
  

      breakOutScene.ballColor = ballColor
    }
  }

  var blockColors: [UIColor] {
    didSet {
      breakOutScene.blockColors = blockColors
    }
  }

  override init(frame: CGRect) {
    assert(false, "Use init(scrollView:) instead.")
    breakOutScene = BreakOutScene(size: frame.size)
    scrollView = UIScrollView()

    scenebackgroundColor = UIColor.whiteColor()
    paddleColor = UIColor.whiteColor()
    ballColor = UIColor.whiteColor()
    blockColors = [UIColor.whiteColor()]

    super.init(frame: frame)
  }


  init(scrollView inScrollView: UIScrollView) {

    let frame = CGRect(x: 0.0, y: -sceneHeight, width: inScrollView.frame.size.width, height: sceneHeight)

    breakOutScene = BreakOutScene(size: frame.size)
    self.scrollView = inScrollView

    scenebackgroundColor = UIColor.whiteColor()
    paddleColor = UIColor.grayColor()
    ballColor = UIColor.blackColor()
    blockColors = [UIColor(white: 0.2, alpha: 1.0), UIColor(white: 0.4, alpha: 1.0), UIColor(white: 0.6, alpha: 1.0)]

    breakOutScene.scenebackgroundColor = scenebackgroundColor
    breakOutScene.paddleColor = paddleColor
    breakOutScene.ballColor = ballColor
    breakOutScene.blockColors = blockColors

    super.init(frame: frame)

    layer.borderColor = UIColor.grayColor().CGColor
    layer.borderWidth = 1.0

    presentScene(StartScene(size: frame.size))
  }

  required init(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }


  func beginRefreshing() {
    isRefreshing = true

    let doors = SKTransition.doorsOpenVerticalWithDuration(0.5)
    presentScene(breakOutScene, transition: doors)
    breakOutScene.updateLabel("Loading...")

    UIView.animateWithDuration(0.4, delay: 0, options: .CurveEaseInOut, animations: { () -> Void in
      self.scrollView.contentInset.top += self.sceneHeight
      }) { (_) -> Void in
        if self.scrollView.contentOffset.y < -60 {
          self.breakOutScene.reset()
          self.breakOutScene.start()
        }
        self.isVisible = true
    }
  }

  func endRefreshing() {
    if (!isDragging || forceEnd) && isVisible {
      self.isVisible = false
      UIView.animateWithDuration(0.4, delay: 0, options: .CurveEaseInOut, animations: { () -> Void in
        self.scrollView.contentInset.top -= self.sceneHeight
        }) { (_) -> Void in
          self.isRefreshing = false
          self.presentScene(StartScene(size: self.frame.size))
      }
    } else {
      breakOutScene.updateLabel("Loading Finished")
      isRefreshing = false
    }
  }
}

extension BreakOutToRefreshView: UIScrollViewDelegate {

  func scrollViewWillBeginDragging(scrollView: UIScrollView) {
    isDragging = true
  }

  func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
    isDragging = false

    if !isRefreshing && scrollView.contentOffset.y + scrollView.contentInset.top < -sceneHeight {
      beginRefreshing()
      targetContentOffset.memory.y = -scrollView.contentInset.top
      delegate?.refreshViewDidRefresh(self)
    }

    if !isRefreshing {
      endRefreshing()
    }

  }

  func scrollViewDidScroll(scrollView: UIScrollView) {
    let frameHeight = frame.size.height
    let yPosition = sceneHeight - (-scrollView.contentInset.top-scrollView.contentOffset.y)*2

    breakOutScene.moveHandle(yPosition)
  }
}

class BreakOutScene: SKScene, SKPhysicsContactDelegate {

  let ballName = "ball"
  let paddleName = "paddle"
  let blockName = "block"
  let backgroundLabelName = "backgroundLabel"

  let ballCategory   : UInt32 = 0x1 << 0
  let backCategory : UInt32 = 0x1 << 1
  let blockCategory  : UInt32 = 0x1 << 2
  let paddleCategory : UInt32 = 0x1 << 3

  var contentCreated = false
  var isStarted = false

  var scenebackgroundColor: UIColor!
  var paddleColor: UIColor!
  var ballColor: UIColor!
  var blockColors: [UIColor]!

  override func didMoveToView(view: SKView) {
    super.didMoveToView(view)
    if !contentCreated {
