Created
November 24, 2017 04:38
-
-
Save Zedd0202/e17e9cf2011e6fc6727ee0ee246c68d1 to your computer and use it in GitHub Desktop.
스와이프시 방향 감지 방법
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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