I want to give support for iOS 8 and above like tableview
row actions with animations like the mail app. I have added the pan gesture to the cell and trying to stop the cell from moving up and down while panning the cell, and how to make it interactive like the iOS mail app.
Any help is really appreciated thanks in advance.
I Am handling the gestures in changed state. I have handled in the delegate -- gestureRecognizerShouldBegin
and its helped in stop panning the cell only in beginning. after starting to pan the cell was able to move up and down.func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
guard let panRecognizer = gestureRecognizer as? UIPanGestureRecognizer else {
return false
}
let velocity = panRecognizer.velocity(in: self.view)
if abs(velocity.y) > abs(velocity.x) {
print("false")
return false
}
print("true")
return true
}
This is handled in selector method
else if(gesture.state == .changed){
print("ended")
let velocity = gesture.velocity(in: self.view)
if (abs(velocity.y) > abs(velocity.x)) {
print("panning upward while panning with touch")
//gesture.setTranslation(CGPoint(x:(frame?.center.x)!,y:(frame?.center.y)!), in: self.view)
}else if(abs(velocity.y) < abs(velocity.x)) {
print("panning in horizontal direction ")
let velocity = gesture.velocity(in: self.view)
let translation = gesture.translation(in: self.view )
gesture.view!.center = CGPoint(x:gesture.view!.center.x + translation.x, y:gesture.view!.center.y + translation.y)
gesture.setTranslation(CGPoint(x:0,y:0), in: self.view)
}
}
You should be changing only your x-coordinate when the panning is more in the x-direction.