Skip to content

Instantly share code, notes, and snippets.

@ohiofi
Last active April 12, 2019 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohiofi/e2bcba7bae53b3c3f261db27d2700eb2 to your computer and use it in GitHub Desktop.
Save ohiofi/e2bcba7bae53b3c3f261db27d2700eb2 to your computer and use it in GitHub Desktop.
// At the bottom of override func didMove()
// add this below the tapGestureRecognizer
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(_:)))
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(_:)))
leftSwipe.direction = .left
rightSwipe.direction = .right
view.addGestureRecognizer(leftSwipe)
view.addGestureRecognizer(rightSwipe)
}
@objc func handleSwipes(_ sender:UISwipeGestureRecognizer) {
if (sender.direction == .left) {
print("Swipe Left")
skater.position.x -= 5
//let labelPosition = CGPoint(x: skater.position.x - 50.0, y: swipeLabel.frame.origin.y)
//swipeLabel.frame = CGRect(x: labelPosition.x, y: labelPosition.y, width: swipeLabel.frame.size.width, height: swipeLabel.frame.size.height)
}
if (sender.direction == .right) {
print("Swipe Right")
skater.position.x += 5
//let labelPosition = CGPoint(x: self.swipeLabel.frame.origin.x + 50.0, y: self.swipeLabel.frame.origin.y)
//swipeLabel.frame = CGRect(x: labelPosition.x, y: labelPosition.y, width: self.swipeLabel.frame.size.width, height: self.swipeLabel.frame.size.height)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment