Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class ViewController: UIViewController, UIScrollViewDelegate, UIGestureRecognizerDelegate {
- @IBOutlet weak var scrollView: UIScrollView!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- self.scrollView.delegate = self
- let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.respondToSwipeGesture(gesture:)))
- swipeUp.direction = UISwipeGestureRecognizerDirection.up
- let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.respondToSwipeGesture(gesture:)))
- swipeDown.direction = UISwipeGestureRecognizerDirection.down
- self.view.addGestureRecognizer(swipeUp)
- self.view.addGestureRecognizer(swipeDown)
- }
- // here are those protocol methods with Swift syntax
- public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
- return true
- }
- public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
- return true
- }
- // Debugging - All Swipes Are Detected Now
- func respondToSwipeGesture(gesture: UIGestureRecognizer) {
- if let swipeGesture = gesture as? UISwipeGestureRecognizer {
- switch swipeGesture.direction {
- case UISwipeGestureRecognizerDirection.down:
- print("Swiped down")
- case UISwipeGestureRecognizerDirection.up:
- print("Swiped up")
- default:
- break
- }
- }
- }
- override func viewDidAppear(_ animated: Bool) {
- scrollView.contentSize.height = 1000
- self.view.layoutIfNeeded()
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement