//cell長(zhǎng)按拖動(dòng)排序
- (void)longPressRecognizer:(UILongPressGestureRecognizer *)longPress{
//獲取長(zhǎng)按的點(diǎn)及cell
CGPoint location = [longPress locationInView:self.myTableView];
NSIndexPath *indexPath = [self.myTableView indexPathForRowAtPoint:location];
UIGestureRecognizerState state = longPress.state;
static UIView *snapView = nil;
static NSIndexPath *sourceIndex = nil;
switch (state) {
case UIGestureRecognizerStateBegan:{
if (indexPath) {
sourceIndex = indexPath;
UITableViewCell *cell = [self.myTableView cellForRowAtIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
snapView = [self customViewWithTargetView:cell];
__block CGPoint center = cell.center;
snapView.center = center;
snapView.alpha = 0.0;
[self.myTableView addSubview:snapView];
[UIView animateWithDuration:0.1 animations:^{
center.y = location.y;
snapView.center = center;
snapView.transform = CGAffineTransformMakeScale(1.05, 1.05);
snapView.alpha = 0.5;
cell.alpha = 0.0;
}];
}
}
break;
case UIGestureRecognizerStateChanged:{
CGPoint center = snapView.center;
center.y = location.y;
snapView.center = center;
UITableViewCell *cell = [self.myTableView cellForRowAtIndexPath:sourceIndex];
cell.alpha = 0.0;
if (indexPath && ![indexPath isEqual:sourceIndex]) {
[self.dataArrayM exchangeObjectAtIndex:indexPath.row withObjectAtIndex:sourceIndex.row];
[self.myTableView moveRowAtIndexPath:sourceIndex toIndexPath:indexPath];
sourceIndex = indexPath;
}
}
break;
default:{
UITableViewCell *cell = [self.myTableView cellForRowAtIndexPath:sourceIndex];
[UIView animateWithDuration:0.25 animations:^{
snapView.center = cell.center;
snapView.transform = CGAffineTransformIdentity;
snapView.alpha = 0.0;
cell.alpha = 1.0;
} completion:^(BOOL finished) {
[snapView removeFromSuperview];
snapView = nil;
}];
sourceIndex = nil;
}
break;
}
}
- (void)dragButtonClick:(UIButton *)button{
//添加長(zhǎng)按手勢(shì)
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressRecognizer:)];
self.longPress = longPress;
longPress.minimumPressDuration = 0.0;
[button addGestureRecognizer:longPress];
}
//截取選中cell
- (UIView *)customViewWithTargetView:(UIView *)target{
UIGraphicsBeginImageContextWithOptions(target.bounds.size, NO, 0);
[target.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIView *snapshot = [[UIImageView alloc] initWithImage:image];
snapshot.layer.masksToBounds = NO;
snapshot.layer.cornerRadius = 0.0;
snapshot.layer.shadowOffset = CGSizeMake(-5.0, 0.0);
snapshot.layer.shadowRadius = 5.0;
snapshot.layer.shadowOpacity = 0.4;
return snapshot;
}
UITableViewCell長(zhǎng)按拖動(dòng)排序
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門罕邀,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)畅形,“玉大人,你說(shuō)我怎么就攤上這事诉探∪瞻荆” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵肾胯,是天一觀的道長(zhǎng)竖席。 經(jīng)常有香客問(wèn)我,道長(zhǎng)敬肚,這世上最難降的妖魔是什么怕敬? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮帘皿,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘畸陡。我一直安慰自己鹰溜,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開(kāi)白布丁恭。 她就那樣靜靜地躺著曹动,像睡著了一般。 火紅的嫁衣襯著肌膚如雪牲览。 梳的紋絲不亂的頭發(fā)上墓陈,一...
- 那天,我揣著相機(jī)與錄音第献,去河邊找鬼贡必。 笑死,一個(gè)胖子當(dāng)著我的面吹牛庸毫,可吹牛的內(nèi)容都是我干的仔拟。 我是一名探鬼主播,決...
- 文/蒼蘭香墨 我猛地睜開(kāi)眼飒赃,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼利花!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起载佳,我...
- 序言:老撾萬(wàn)榮一對(duì)情侶失蹤炒事,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后蔫慧,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體挠乳,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了欲侮。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片崭闲。...
- 正文 年R本政府宣布牍戚,位于F島的核電站,受9級(jí)特大地震影響虑粥,放射性物質(zhì)發(fā)生泄漏如孝。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一娩贷、第九天 我趴在偏房一處隱蔽的房頂上張望第晰。 院中可真熱鬧,春花似錦彬祖、人聲如沸茁瘦。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)甜熔。三九已至,卻和暖如春突倍,著一層夾襖步出監(jiān)牢的瞬間腔稀,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓秕磷,卻偏偏與公主長(zhǎng)得像炕淮,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子跳夭,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 前言 前不久有跟小伙伴談?wù)摰疥P(guān)于長(zhǎng)按cell來(lái)拖動(dòng)排序的問(wèn)題涂圆,筆者在github上找到一個(gè)相關(guān)資料moayes/U...
- 效果圖: github下載地址:DHDragableCellTableView 使用 將tableView繼承與D...
- iOS 手勢(shì)操作:拖動(dòng)荞下、捏合伶选、旋轉(zhuǎn)、點(diǎn)按尖昏、長(zhǎng)按考蕾、輕掃、自定義:轉(zhuǎn)載:http://www.cnblogs.com/...
- 1矮嫉、UIGestureRecognizer 介紹 手勢(shì)識(shí)別在 iOS 中非常重要,他極大地提高了移動(dòng)設(shè)備的使用便捷...