Skip to content

Instantly share code, notes, and snippets.

@M0rtyMerr
Last active January 20, 2019 11:09
Show Gist options
  • Save M0rtyMerr/7caf8366fe4c507d0dfc36b5f553c4c1 to your computer and use it in GitHub Desktop.
Save M0rtyMerr/7caf8366fe4c507d0dfc36b5f553c4c1 to your computer and use it in GitHub Desktop.
Old plain way of handling gestures vs RxGesture framework. Rx frameworks can be found here - https://github.com/RxSwiftCommunity/RxGesture
// Native way
override func viewDidLoad() {
super.viewDidLoad()
let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.handlePan))
panGestureRecognizer.maximumNumberOfTouches = 3
view.addGestureRecognizer(panGestureRecognizer)
}
@objc private func handlePan(_ sender: UIPanGestureRecognizer) {
switch sender.state {
case .ended:
let translation = sender.translation(in: view)
print(translation)
default:
break
}
}
//____________________//
// RxGesture
override func viewDidLoad() {
super.viewDidLoad()
view.rx
.panGesture { gestureRecognizer, _ in
gestureКecognizer.maximumNumberOfTouches = 3
}
.when(.ended)
.asTranslation()
.bind { print($0) }
.disposed(by: disposeBag)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment