pangestures 像 iOS 中的邮件应用程序一样交互
pangestures interactive like mail app in iOS
我想支持 iOS 8 及更高版本,例如 tableview
带有动画的行操作,例如邮件应用程序。我已将平移手势添加到单元格并试图阻止单元格在平移单元格时上下移动,以及如何使其像 iOS 邮件应用程序一样具有交互性。
非常感谢任何帮助提前致谢。
我正在处理状态改变的手势。我已经在委托中处理过 -- gestureRecognizerShouldBegin
并且它仅在开始时帮助停止平移单元格。开始平移后,单元格能够向上移动并且 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)
}
}
当平移更多地在 x 方向上时,您应该只更改 x 坐标。
我想支持 iOS 8 及更高版本,例如 tableview
带有动画的行操作,例如邮件应用程序。我已将平移手势添加到单元格并试图阻止单元格在平移单元格时上下移动,以及如何使其像 iOS 邮件应用程序一样具有交互性。
非常感谢任何帮助提前致谢。
我正在处理状态改变的手势。我已经在委托中处理过 -- gestureRecognizerShouldBegin
并且它仅在开始时帮助停止平移单元格。开始平移后,单元格能够向上移动并且 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)
}
}
当平移更多地在 x 方向上时,您应该只更改 x 坐标。