我試圖在我的collectionViewCell中實現UISwipeGestureRecognizer,因此當您向左滑動時,單元格消失。我試圖實現(我找不到方法)是爲了刷動畫,所以當我向左滑動單元格時,它會消失並帶有淡化效果。這是代碼我有方法cellForItemAtindexPath
UISwipeGestureRecognizer動畫
let cSelector = #selector(reset(sender:))
let UpSwipe = UISwipeGestureRecognizer(target: self, action: cSelector)
UpSwipe.direction = UISwipeGestureRecognizerDirection.left
cell.addGestureRecognizer(UpSwipe)
的方法
func reset(sender: UISwipeGestureRecognizer) {
let cell = sender.view as! UICollectionViewCell
let i = self.collectionView?.indexPath(for: cell)!.item
self.messages.remove(at: i!)
self.collectionView?.reloadData()
}
由於內!
編輯: 我想我找到了一個最簡單的方法來做到這一點,但我有一些麻煩。我嘗試在單元中實現UIPanGestureRecognizer。這是怎麼看起來像......
cellForItemAt
let gestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan(gestureRecognizer:)))
cell.addGestureRecognizer(gestureRecognizer)
func handlePan(gestureRecognizer: UIPanGestureRecognizer) {
if gestureRecognizer.state == .began {
// When the drag is first recognized, you can get the starting coordinates here
}
if gestureRecognizer.state == .changed {
let translation = gestureRecognizer.translation(in: self.view)
// Translation has both .x and .y values
if translation.x == translation.x - 100 {
//Method i putted before
reset(sender: gestureRecognizer)
}
//print(translation.x, translation.y)
}
}
我試圖找到該單元格的座標,所以當它在一個點的方法細胞左側,細胞星星會出現某種淡入淡出的動畫,然後消失。
任何幫助?謝謝!!!
是的,我想刪除它與動畫。 – Edwjonn
這可能會幫助你https://stackoverflow.com/questions/16690831/uicollectionview-animations-insert-delete-items – Krunal
事情是,我的單元格寬度是collectionView的整個寬度,所以我正在尋找一個滑動左旋效應;像UITableView,但與我有的代碼。當然快! – Edwjonn