Reputation: 380
I have pangesture recognizer in custom UITableViewCell
and I want to disable it during table view scrolling. Is it possible to detect in custom UITableViewCell
is table view is scrolling?
Upvotes: 2
Views: 676
Reputation: 658
Use this extension for detect specific tableview scrolling in iOS Swift
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == tableName {
// write logic for tableview disble scrolling
}
}
}
Upvotes: 1
Reputation: 1238
As @jarvis12 mentioned in comment, UITableView
inherits from UIScrollView
and you can take advantage of its delegate methods.
Add a global bool variable which will act as a flag to check current state of scrolling.
var isScrolling = false
Add two UIScrollView
delegate methods and update isScrolling
variable as below:
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
self.isScrolling = true
}
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
self.isScrolling = false
}
In your UITableViewCell
simply add following if condition:
if isScrolling {
//disable pan gesture
}
else {
//enable pan gesture
}
Upvotes: 1