我正在尝试创建一个类似于tableView滑动的功能来显示删除按钮,唯一的区别是我显示了多个按钮,并在collectionView
内的collectionViewCell
上实现了它。我希望能够将内部collectionView向右滑动,并在左侧将多个选项按钮捕捉到视图中。
这样的事情:
我明白我可能需要使用UIPanGestureRecognizer
,对我来说问题是panView to pan嵌套在另一个collectionView
中,我不确定如何使用UIGestureRecognizer
正确,以便细胞一起滑动,按钮会进入视图。
非常感谢任何建议。
答案 0 :(得分:0)
在集合视图中设置委托以获取操作
protocol ColumnBookCellDelegate: class {
func deleteBook(_ book: Book)
}
class ColumnBookCell: AZCollectionViewCell{
weak var deleteDelegate: ColumnBookCellDelegate?
var canBeRemove: Bool = false{
didSet{
if self.canBeRemove{
let swipeL = UISwipeGestureRecognizer(target: self, action: #selector(self.showDelete))
swipeL.numberOfTouchesRequired = 1
swipeL.direction = .left
self.addGestureRecognizer(swipeL)
let swipeR = UISwipeGestureRecognizer(target: self, action: #selector(self.hideDelete))
swipeR.numberOfTouchesRequired = 1
swipeR.direction = .right
self.addGestureRecognizer(swipeR)
}
}
}
// Show Delete Button
func showDelete(){
// unhidden button here
// self.button.isHidden = false
UIView.animate(withDuration: 0.2) {
self.layoutIfNeeded()
}
}
// Hide Delete Button
func hideDelete(){
// hidden button here
// self.button.isHidden = true
// self.deleteButton.aZConstraints.width?.constant = 0
UIView.animate(withDuration: 0.2) {
self.layoutIfNeeded()
}
}
// Delete Action
func deleteAction(){
self.deleteDelegate?.deleteBook(self.book)
self.hideDelete()
}
// blob blob blob
}