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

关于戒烟网站怎么做asp的公司网站

关于戒烟网站怎么做,asp的公司网站,沪佳装修官方电话,金融网站的设计效果图 原理 就是设置collectionView调整顺序的代理方法,这里要注意一点 调整过代理方法之后,一定要修改数据源,否则导致错乱。 还有就是在collectionView上面添加一个长按手势,在长按手势的不同阶段,调用collectionV…

效果图

请添加图片描述

原理

就是设置collectionView调整顺序的代理方法,这里要注意一点
调整过代理方法之后,一定要修改数据源,否则导致错乱。
还有就是在collectionView上面添加一个长按手势,在长按手势的不同阶段,调用collectionView 调整顺序的系统方法 beginInteractiveMovementForItemAtIndexPath
等等

代码

//
//  ViewController.m
//  LBEditCollectionCellOrder
//
//  Created by mac on 2024/6/10.
//#import "ViewController.h"
#import "LBOrderCell.h"@interface ViewController () <UICollectionViewDelegate, UICollectionViewDataSource>@property (nonatomic, strong) UICollectionView *collectionView;@property (nonatomic, strong) UILongPressGestureRecognizer *longPressRecognizer;@property (nonatomic, strong) NSMutableArray *dataArray;@property (nonatomic, assign) BOOL inDrag;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];[self.view addSubview:self.collectionView];[self.collectionView reloadData];[self.collectionView addGestureRecognizer:self.longPressRecognizer];// Do any additional setup after loading the view.
}#pragma mark - 手势拖拽- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath
{//最后一个不能拖拽return self.dataArray.count > indexPath.item;
}- (NSIndexPath *)collectionView:(UICollectionView *)collectionView targetIndexPathForMoveOfItemFromOriginalIndexPath:(NSIndexPath *)originalIndexPath atCurrentIndexPath:(NSIndexPath *)currentIndexPath toProposedIndexPath:(NSIndexPath *)proposedIndexPath
{if ([self collectionView:collectionView canMoveItemAtIndexPath:proposedIndexPath]) {return proposedIndexPath;}return originalIndexPath;
}- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{NSString *title = [self.dataArray objectAtIndex:sourceIndexPath.item];if (!title) {return;}NSInteger targetIdx = destinationIndexPath.item;NSLog(@"修改之前的数量%ld",self.dataArray.count);[self.dataArray removeObject:title];NSLog(@"这里的%@", title);NSLog(@"这是否包含%d", [self.dataArray containsObject:title]);[self.dataArray insertObject:title atIndex:targetIdx];NSLog(@"修改之后的数量%ld", self.dataArray.count);
}#pragma mark - UICollectionViewDelegate, UICollectionViewDataSource- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{return 1;
}- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{return self.dataArray.count;
}- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{LBOrderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([LBOrderCell class]) forIndexPath:indexPath];[cell updateWithText:self.dataArray[indexPath.item]];return cell;
}#pragma mark - action- (void)longPressRecognizer:(UILongPressGestureRecognizer *)gestureRecognizer
{CGPoint point = [gestureRecognizer locationInView:self.collectionView];switch (gestureRecognizer.state) {case UIGestureRecognizerStateBegan: {NSIndexPath *selectedIndexPath = [self.collectionView indexPathForItemAtPoint:point];if (selectedIndexPath) {[self.collectionView beginInteractiveMovementForItemAtIndexPath:selectedIndexPath];}break;}case UIGestureRecognizerStateChanged: {[self.collectionView updateInteractiveMovementTargetPosition:point];break;;}case UIGestureRecognizerStateEnded: {[self.collectionView endInteractiveMovement];break;}default:{[self.collectionView cancelInteractiveMovement];}break;}
}#pragma mark - lazy load- (UICollectionView *)collectionView
{if (!_collectionView) {UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;CGFloat w = (CGRectGetWidth(self.view.bounds) - 2 * 8 - 2 * 20.5)/3;CGFloat space = 8;layout.itemSize = CGSizeMake(w, w);layout.minimumLineSpacing = space;layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);self.view.clipsToBounds = YES;_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 100, CGRectGetWidth(self.view.bounds), 350) collectionViewLayout:layout];[_collectionView registerClass:[LBOrderCell class] forCellWithReuseIdentifier:NSStringFromClass([LBOrderCell class])];_collectionView.dataSource = self;_collectionView.delegate = self;_collectionView.backgroundColor = [UIColor cyanColor];}return _collectionView;
}- (UILongPressGestureRecognizer *)longPressRecognizer
{if (!_longPressRecognizer) {_longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressRecognizer:)];_longPressRecognizer.minimumPressDuration = 0.3;}return _longPressRecognizer;
}- (NSMutableArray *)dataArray
{if (!_dataArray) {NSArray *array = @[@"1", @"2", @"3", @"4", @"5", @"6",@"7", @"8", @"9", @"10", @"11", @"12"];_dataArray = [NSMutableArray array];[_dataArray addObjectsFromArray:array];}return _dataArray;
}@end

链接: link
如果对您有帮助,请给一个star

http://www.yayakq.cn/news/340487/

相关文章:

  • 邢台网站制作地址附近电脑培训班位置
  • wordpress 中介网站体育新闻最新消息
  • 网站如何做视频的软件成都科盛兴网站建设有限公司
  • 营销型网站重要性建设网站用什么代码写好呢
  • 网站免费php空间申请网站开发设计流程
  • 郑州网站推广报价wordpress文章幻灯片代码
  • 企业集团网站建设方案论文合肥网站建设多少钱
  • 花卉网站建设策划方案扬州建设局网站
  • 迈网科技 官方网站产品艺术设计专业
  • 汕头行业网站新1站网站建设
  • 网站的文件夹天津建设工程信息网密码
  • logo设计网站知乎网站制作基本规则
  • 如何建设学校门户网站如何利用网站赚钱
  • 网站原创文章不收录大唐网站设计
  • 怎样的网站打开速度块淘宝客的优惠卷网站怎么做的
  • 视频网站怎么做统计pjax wordpress主题
  • 网站开发课题研究背景易企秀网站怎么做轮播图
  • 网站建设方案2018什么自己做网站吗
  • 建设高端网站微信一键登录网站怎么做
  • 陆良县住房和城乡建设局网站网站建设php心得体会
  • seo企业网站优化django网站开发实例源码
  • 门户网站模板 html高端网站定制平台
  • 网站建设方案的需求分析网上怎么做销售
  • 寻找石家庄网站建设网站平台建设公司经营范围
  • 全功能电子商务网站建设广西壮族自治区地图全图
  • 网站开发完整教程网页设计板式类型
  • 做配资 怎么在网站联系客户怎么在网上注册公司
  • 湖南智能网站建设平台企业官网模板图下载
  • 郑州网站建设与制作便利的菏泽网站建设
  • js网站统计超酷win8风格企业网站织梦模板