Last active
January 20, 2019 11:09
-
-
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
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
// 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