This is my ViewController1
And this is my GestureManager class:
It won't throw any error or warnings, it just does not work.
Code Block class ViewController1: UIViewController { fileprivate lazy var gestureManager: GestureManager = { return GestureManager(vc: self) }() override func viewDidLoad() { super.viewDidLoad() } }
And this is my GestureManager class:
Code Block class GestureManager { var appDelegate = UIApplication.shared.delegate as! AppDelegate var vc: UIViewController? init(vc: UIViewController) { print("init controller") self.vc = vc let swipeRight = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:))) swipeRight.direction = .right let swipeLeft = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:))) swipeLeft.direction = .left let swipeUp = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:))) swipeUp.direction = .up let swipeDown = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:))) swipeDown.direction = .down vc.view.addGestureRecognizer(swipeRight) vc.view.addGestureRecognizer(swipeLeft) vc.view.addGestureRecognizer(swipeUp) vc.view.addGestureRecognizer(swipeDown) } @objc func respondToSwipeGesture(_ gesture : UIGestureRecognizer) { print("this got fired") if let swipeGesture = gesture as? UISwipeGestureRecognizer { switch swipeGesture.direction { case .right: print("swiped right!") case .left: print("Swiped left") case .up: print("Swiped up") case .down: print("Swiped down!!!") default: return } } } }
It won't throw any error or warnings, it just does not work.