Skip to content

Instantly share code, notes, and snippets.

@Zedd0202
Created November 24, 2017 04:38
Show Gist options
  • Save Zedd0202/e17e9cf2011e6fc6727ee0ee246c68d1 to your computer and use it in GitHub Desktop.
Save Zedd0202/e17e9cf2011e6fc6727ee0ee246c68d1 to your computer and use it in GitHub Desktop.
스와이프시 방향 감지 방법
import UIKit
import AVFoundation
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
addSwipe()
}
func addSwipe() {
let directions: [UISwipeGestureRecognizerDirection] = [.right, .left, .up, .down]
for direction in directions {
let gesture = UISwipeGestureRecognizer(target: self, action: #selector(self.handleSwipe))
gesture.direction = direction
self.view.addGestureRecognizer(gesture)
}
}
func handleSwipe(sender: UISwipeGestureRecognizer) {
switch sender.direction {
case UISwipeGestureRecognizerDirection.right:
print("Swiped right")
case UISwipeGestureRecognizerDirection.down:
print("Swiped down")
case UISwipeGestureRecognizerDirection.left:
print("Swiped left")
case UISwipeGestureRecognizerDirection.up:
print("Swiped up")
default:
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment