当前位置: 首页 > news >正文

微网站建设资讯百度推广方式

微网站建设资讯,百度推广方式,wordpress后台怎么登入,福州网站建设服务价格最实惠拖拽排序是新闻类的App可以说是必有的交互设计,如今日头条,网易新闻等。拖拽排序是一个交互体验非常好的设计,简单,方便。 ####实现方案 1.给CollectionViewCell添加一个长按手势,通过协议把手势传递到collectionView…

拖拽排序是新闻类的App可以说是必有的交互设计,如今日头条,网易新闻等。拖拽排序是一个交互体验非常好的设计,简单,方便。

####实现方案

1.给CollectionViewCell添加一个长按手势,通过协议把手势传递到collectionView所在的控制器中。- (void)awakeFromNib{self.layer.cornerRadius = 3;self.layer.masksToBounds = YES;//给每个cell添加一个长按手势UILongPressGestureRecognizer * longPress =[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];longPress.delegate = self;[self addGestureRecognizer:longPress];}

- (void)longPress:(UILongPressGestureRecognizer *)longPress{if (self.delegate && [self.delegate respondsToSelector:@selector(longPress:)]) {[self.delegate longPress:longPress];}
}

2.开始长按时对cell进行截图,并隐藏cell。

- (void)longPress:(UILongPressGestureRecognizer *)longPress{//记录上一次手势的位置static CGPoint startPoint;//触发长按手势的cellMovingCell * cell = (MovingCell *)longPress.view;//开始长按if (longPress.state == UIGestureRecognizerStateBegan) {[self shakeAllCell];//获取cell的截图_snapshotView  = [cell snapshotViewAfterScreenUpdates:YES];_snapshotView.center = cell.center;[_collectionView addSubview:_snapshotView];_indexPath= [_collectionView indexPathForCell:cell];_originalCell = cell;_originalCell.hidden = YES;startPoint = [longPress locationInView:_collectionView];}

3、在手势移动的时候,移动截图视图,用遍历的方法求出截图移动到哪个cell的位置,再调用系统的api交换这个cell和隐藏cell的位置,并且数据源中的数据也需要调整顺序

    //手势移动的时候else if (longPress.state == UIGestureRecognizerStateChanged){CGFloat tranX = [longPress locationOfTouch:0 inView:_collectionView].x - startPoint.x;CGFloat tranY = [longPress locationOfTouch:0 inView:_collectionView].y - startPoint.y;//设置截图视图位置_snapshotView.center = CGPointApplyAffineTransform(_snapshotView.center, CGAffineTransformMakeTranslation(tranX, tranY));startPoint = [longPress locationOfTouch:0 inView:_collectionView];//计算截图视图和哪个cell相交for (UICollectionViewCell *cell in [_collectionView visibleCells]) {//跳过隐藏的cellif ([_collectionView indexPathForCell:cell] == _indexPath) {continue;}//计算中心距CGFloat space = sqrtf(pow(_snapshotView.center.x - cell.center.x, 2) + powf(_snapshotView.center.y - cell.center.y, 2));//如果相交一半且两个视图Y的绝对值小于高度的一半就移动if (space <= _snapshotView.bounds.size.width * 0.5 && (fabs(_snapshotView.center.y - cell.center.y) <= 
_snapshotView.bounds.size.height * 0.5)) {_nextIndexPath = [_collectionView indexPathForCell:cell];if (_nextIndexPath.item > _indexPath.item) {for (NSUInteger i = _indexPath.item; i < _nextIndexPath.item ; i ++) {[self.array exchangeObjectAtIndex:i withObjectAtIndex:i + 1];}}else{for (NSUInteger i = _indexPath.item; i > _nextIndexPath.item ; i --) {[self.array exchangeObjectAtIndex:i withObjectAtIndex:i - 1];}}//移动[_collectionView moveItemAtIndexPath:_indexPath toIndexPath:_nextIndexPath];//设置移动后的起始indexPath_indexPath = _nextIndexPath;break;}}

4.手势停止时,移除截图的view,显示隐藏cell

//手势停止时
}else if(longPress.state == UIGestureRecognizerStateEnded){[self stopShake];[_snapshotView removeFromSuperview];_originalCell.hidden = NO;
}

####其他代码还可以进一步封装,写一个数据管理类dataTool,dataTool作为collectionView的数据源,所有的数据源方法都写到dataTool类中。手势的代理方法也在里面实现,这样控制器会简洁很多,控制器就不需要关注拖拽排序的具体逻辑了。大家有空可以自己写写看,也许你们有更好的处理方案,可以评论交流一下。github地址:https://github.com/HelloYeah/DraggingSort



http://www.lbrq.cn/news/2567017.html

相关文章:

  • 东莞做棋牌网站建设网站的seo如何优化
  • 网站积分解决方案网址大全名称
  • 上海新闻网首页优化服务公司
  • win7 iis 新建网站福州网seo
  • 做产品代理上哪个网站好希爱力
  • 数据推广是干什么的卢镇seo网站优化排名
  • 南昌哪里可以做电商网站百度广告推广平台
  • 智能网站开发工具seo和sem
  • 网站怎么添加百度商桥电商培训视频教程
  • 可以做请柬的网站互联网推广平台有哪些
  • 网站建设背景怎么写海外推广解决方案
  • 服务器如何做网站南宁市优化网站公司
  • iis怎么查看网站的域名巨量算数数据分析入口
  • wordpress防镜像seo关键词优化要多少钱
  • seo站内站怎么做手机百度网页版
  • 如何建设国际网站首页数据分析师报考官网
  • 徐州做网站的哪个好在线外链工具
  • 网站如何关闭2019网站seo
  • 沈阳男科医院哪家医院好seo软件优化
  • wordpress 代做网站拓客平台有哪些
  • 中国建设银行网站 公司机构客户佛山网站建设公司
  • 网站集约化平台建设分析专业网站优化
  • 12380网站建设情况汇报深圳网络推广引流
  • 建设一个旅游网站毕业设计百度店铺怎么入驻
  • wordpress 页面开发教程马鞍山网站seo
  • 河南代做网站semikron
  • 厦门建设与管理局网站优化系统的软件
  • 狗和人做愛网站谁知道好推建站
  • 北京建站公司哪个好百度识图在线使用一下
  • 网站的构造西安今天刚刚发生的新闻
  • 力扣 hot100 Day63
  • web:js的模块导出/导入
  • 【计算机网络】Socket网络编程
  • k8s使用 RBAC 鉴权
  • Flutter镜像替换
  • 从游戏NPC到手术助手:Agent AI重构多模态交互,具身智能打开AGI新大门