長按移動cell

2021-07-05 12:33:29 字數 1325 閱讀 3333

前言: 之前見過瀑布流中的cell,由手勢拖動變換位置的效果,一直覺得很炫很神奇。今天無意在破船之家看到了這種效果的實現方法。最核心的位置變換只需掉倆個方法,然後由系統完成。所以很簡單,沒有想象中的那麼複雜。

我們先從簡單的tableview開始。

效果如下

實現過程

**

新增長按手勢的**就不列出來了,這裡是處理手勢事件的方法。

- (void)handlelongpress:(uilongpressgesturerecognizer *)longpress

completion:^(bool finished) ];}}

else

if (longpress.state == uigesturerecognizerstatechanged)

}else

if (longpress.state == uigesturerecognizerstateended)

completion:^(bool finished) ];

}}- (uiview *)snapshotinview:(uiview *)inputview

if (!currentindexpath) return; 因為如果選到了section的段頭上,currentindexpath是空值。所以要判斷。

sourceindexpath 表示的是交換後源cell的索引。也就是cell移動到了哪個位置上。

移動的核心**就這倆句,[self.datas exchangeobjectatindex:currentindexpath.row withobjectatindex:sourceindexpath.row];和[self.tableview moverowatindexpath:sourceindexpath toindexpath:currentindexpath];先更新資料來源,然後更新ui,這個沒什麼好講的了。最後別忘記sourceindexpath = currentindexpath;移動後源cell的位置也發生變化,所以要更新哦。

collectionview和上面的過程幾乎一模一樣。

附上效果圖

tableview的demo

collectionview的demo

移動端長按事件

lang en charset utf 8 name viewport content width device width,initial scale 1.0 documenttitle head src js jquery.min.js script li style body id style...

在cell中新增長按手勢彈出UIAlertView

首先在cell當中敲入 uilongpressgesturerecognizer longpressgesture uilongpressgesturerecognizer alloc initwithtarget self action selector celllongpress cell ad...

移動端 ios 長按複製相容方案

移動端頁面,需要複製一段文字碼。在ios中,長按文字區域,預設選中的範圍,超出了我長按的文字區域,把上面的和下面的另乙個div的文字也給我包含進來了,並不是我想要的!舉個例子 如下圖 1.我長按的區域是紅色方框內的區域,想要複製框裡的文字內容。2.結果卻是下圖,即便 ios 上能再稍微操作一下 變成...