diff --git a/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionView.h b/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionView.h index 91ab2a19..ad85b551 100644 --- a/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionView.h +++ b/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionView.h @@ -29,12 +29,12 @@ #import "BMLongPressDragCellCollectionViewDataSource.h" /* - - (NSArray *)dataSourceWithDragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView { + - (NSArray *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView { return self.dataSourceArray; // 此协议方法里返回数据源 } - - (void)dragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(nullable NSArray *)newDataArray { + - (void)dragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(nullable NSArray *> *)newDataArray { self.dataSourceArray = [newDataArray mutableCopy]; // 此协议方法里保存数据源 } diff --git a/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionViewDataSource.h b/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionViewDataSource.h index 7af0c3bb..dfb56760 100644 --- a/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionViewDataSource.h +++ b/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionViewDataSource.h @@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN return self.dataArray; } */ -- (nullable NSArray *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView; +- (nullable NSArray *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView; @end diff --git a/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionViewDelegate.h b/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionViewDelegate.h index 25a114d9..cd3789b4 100644 --- a/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionViewDelegate.h +++ b/BMLongPressDragCellCollectionView/BMLongPressDragCellCollectionViewDelegate.h @@ -36,11 +36,11 @@ NS_ASSUME_NONNULL_BEGIN @param dragCellCollectionView dragCellCollectionView @param newDataArray 最新的数据源,需要使用者保存,在拖拽的时候 Cell 已经移动,需保存最新的数据源 - - (void)dragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(nullable NSArray *)newDataArray { + - (void)dragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(nullable NSArray *> *)newDataArray { self.dataArray = [newDataArray copy]; } */ -- (void)dragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(nullable NSArray *)newDataArray; +- (void)dragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(nullable NSArray *> *)newDataArray; @optional diff --git a/Example/BMLongPressDragCellCollectionView.xcodeproj/project.pbxproj b/Example/BMLongPressDragCellCollectionView.xcodeproj/project.pbxproj index 0c3cc157..108e2d0e 100644 --- a/Example/BMLongPressDragCellCollectionView.xcodeproj/project.pbxproj +++ b/Example/BMLongPressDragCellCollectionView.xcodeproj/project.pbxproj @@ -37,8 +37,6 @@ 056CBE6B24AC5D8300FAD464 /* SwiftDemoVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 056CBE6924AC5D8300FAD464 /* SwiftDemoVC.swift */; }; 056CBE6C24AC5D8300FAD464 /* SwiftDemoVC.xib in Resources */ = {isa = PBXBuildFile; fileRef = 056CBE6A24AC5D8300FAD464 /* SwiftDemoVC.xib */; }; 056CBE6F24AC5FC000FAD464 /* SwiftDemoCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 056CBE6D24AC5FC000FAD464 /* SwiftDemoCollectionViewCell.swift */; }; - 059F341824AC705200634413 /* SwiftDemoXibCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 059F341624AC705200634413 /* SwiftDemoXibCollectionViewCell.swift */; }; - 059F341924AC705200634413 /* SwiftDemoXibCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 059F341724AC705200634413 /* SwiftDemoXibCollectionViewCell.xib */; }; 05C4FEBD24A1EB0000260E73 /* BMChannelEditVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 05C4FEA624A1EB0000260E73 /* BMChannelEditVC.m */; }; 05C4FEBE24A1EB0000260E73 /* BMChannelEditVC.xib in Resources */ = {isa = PBXBuildFile; fileRef = 05C4FEA724A1EB0000260E73 /* BMChannelEditVC.xib */; }; 05C4FEBF24A1EB0000260E73 /* BMChannelModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 05C4FEAA24A1EB0000260E73 /* BMChannelModel.m */; }; @@ -123,8 +121,6 @@ 056CBE6924AC5D8300FAD464 /* SwiftDemoVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDemoVC.swift; sourceTree = ""; }; 056CBE6A24AC5D8300FAD464 /* SwiftDemoVC.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SwiftDemoVC.xib; sourceTree = ""; }; 056CBE6D24AC5FC000FAD464 /* SwiftDemoCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDemoCollectionViewCell.swift; sourceTree = ""; }; - 059F341624AC705200634413 /* SwiftDemoXibCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDemoXibCollectionViewCell.swift; sourceTree = ""; }; - 059F341724AC705200634413 /* SwiftDemoXibCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SwiftDemoXibCollectionViewCell.xib; sourceTree = ""; }; 05C4FEA524A1EB0000260E73 /* BMChannelEditVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BMChannelEditVC.h; sourceTree = ""; }; 05C4FEA624A1EB0000260E73 /* BMChannelEditVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BMChannelEditVC.m; sourceTree = ""; }; 05C4FEA724A1EB0000260E73 /* BMChannelEditVC.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BMChannelEditVC.xib; sourceTree = ""; }; @@ -456,8 +452,6 @@ 056CBE6924AC5D8300FAD464 /* SwiftDemoVC.swift */, 056CBE6A24AC5D8300FAD464 /* SwiftDemoVC.xib */, 056CBE6D24AC5FC000FAD464 /* SwiftDemoCollectionViewCell.swift */, - 059F341624AC705200634413 /* SwiftDemoXibCollectionViewCell.swift */, - 059F341724AC705200634413 /* SwiftDemoXibCollectionViewCell.xib */, ); path = Swift; sourceTree = ""; @@ -754,7 +748,6 @@ 05C4FEBE24A1EB0000260E73 /* BMChannelEditVC.xib in Resources */, 0529D8042493795400EA22B9 /* BMAlipay2VC.xib in Resources */, 056CBE6C24AC5D8300FAD464 /* SwiftDemoVC.xib in Resources */, - 059F341924AC705200634413 /* SwiftDemoXibCollectionViewCell.xib in Resources */, 6003F5A9195388D20070C39A /* Images.xcassets in Resources */, 6003F598195388D20070C39A /* InfoPlist.strings in Resources */, 0529D8092493795400EA22B9 /* BMAlipay2HeaderView.xib in Resources */, @@ -858,7 +851,6 @@ 0529D7F92493795400EA22B9 /* BMModel.m in Sources */, 056CBE6B24AC5D8300FAD464 /* SwiftDemoVC.swift in Sources */, 0529D8122493795400EA22B9 /* BMImageCell.m in Sources */, - 059F341824AC705200634413 /* SwiftDemoXibCollectionViewCell.swift in Sources */, 0529D7FC2493795400EA22B9 /* BMTestSizeVC.m in Sources */, 0529D8CB2493795400EA22B9 /* main.m in Sources */, 05C4FEC024A1EB0000260E73 /* BMChannelEditCell.m in Sources */, @@ -935,6 +927,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -959,7 +952,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -989,6 +982,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -1006,8 +1000,9 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; diff --git a/Example/BMLongPressDragCellCollectionView/Demo/Classes/AliPay/Alipay1/Controller/BMAlipayVC.m b/Example/BMLongPressDragCellCollectionView/Demo/Classes/AliPay/Alipay1/Controller/BMAlipayVC.m index db8ebcde..8367c211 100644 --- a/Example/BMLongPressDragCellCollectionView/Demo/Classes/AliPay/Alipay1/Controller/BMAlipayVC.m +++ b/Example/BMLongPressDragCellCollectionView/Demo/Classes/AliPay/Alipay1/Controller/BMAlipayVC.m @@ -18,7 +18,7 @@ @interface BMAlipayVC () *dataSourceArray; +@property (strong, nonatomic) NSMutableArray *> *dataSourceArray; @end @@ -69,23 +69,22 @@ - (void)dragCellAlpha { [self presentViewController:alertVC animated:YES completion:nil]; } -- (NSMutableArray *)dataSourceArray { + +- (NSMutableArray *> *)dataSourceArray { if (!_dataSourceArray) { - _dataSourceArray = [@[] mutableCopy]; - - [_dataSourceArray addObject:[BMAlipayModel modelWithTitle:@"转账" iconName:@"转账"]]; - [_dataSourceArray addObject:[BMAlipayModel modelWithTitle:@"信用卡还款" iconName:@"信用卡"]]; - [_dataSourceArray addObject:[BMAlipayModel modelWithTitle:@"充值中心" iconName:@"充值中心"]]; - [_dataSourceArray addObject:[BMAlipayModel modelWithTitle:@"芝麻信用" iconName:@"芝麻信用"]]; - - [_dataSourceArray addObject:[BMAlipayModel modelWithTitle:@"共享单车" iconName:@"091共享单车 copy"]]; - [_dataSourceArray addObject:[BMAlipayModel modelWithTitle:@"花呗" iconName:@"花呗"]]; - [_dataSourceArray addObject:[BMAlipayModel modelWithTitle:@"滴滴出行" iconName:@"滴滴出行"]]; - [_dataSourceArray addObject:[BMAlipayModel modelWithTitle:@"火车票机票" iconName:@"火车票"]]; - - [_dataSourceArray addObject:[BMAlipayModel modelWithTitle:@"来分期" iconName:@"分期"]]; - [_dataSourceArray addObject:[BMAlipayModel modelWithTitle:@"商家服务" iconName:@"商家服务2"]]; - [_dataSourceArray addObject:[BMAlipayModel modelWithTitle:@"ofo小黄车" iconName:@"ofo共享单车"]]; + NSMutableArray *arr = [@[] mutableCopy]; + [arr addObject:[BMAlipayModel modelWithTitle:@"转账" iconName:@"转账"]]; + [arr addObject:[BMAlipayModel modelWithTitle:@"信用卡还款" iconName:@"信用卡"]]; + [arr addObject:[BMAlipayModel modelWithTitle:@"充值中心" iconName:@"充值中心"]]; + [arr addObject:[BMAlipayModel modelWithTitle:@"芝麻信用" iconName:@"芝麻信用"]]; + [arr addObject:[BMAlipayModel modelWithTitle:@"共享单车" iconName:@"091共享单车 copy"]]; + [arr addObject:[BMAlipayModel modelWithTitle:@"花呗" iconName:@"花呗"]]; + [arr addObject:[BMAlipayModel modelWithTitle:@"滴滴出行" iconName:@"滴滴出行"]]; + [arr addObject:[BMAlipayModel modelWithTitle:@"火车票机票" iconName:@"火车票"]]; + [arr addObject:[BMAlipayModel modelWithTitle:@"来分期" iconName:@"分期"]]; + [arr addObject:[BMAlipayModel modelWithTitle:@"商家服务" iconName:@"商家服务2"]]; + [arr addObject:[BMAlipayModel modelWithTitle:@"ofo小黄车" iconName:@"ofo共享单车"]]; + _dataSourceArray = @[arr].mutableCopy; } return _dataSourceArray; } @@ -104,25 +103,31 @@ - (UICollectionViewFlowLayout *)collectionViewFlowLayout { return _collectionViewFlowLayout; } -- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { +- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return self.dataSourceArray.count; } +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { + return self.dataSourceArray[section].count; +} + - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ return [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; } + - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(BMAlipayCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath { - cell.model = self.dataSourceArray[indexPath.row]; + cell.model = self.dataSourceArray[indexPath.section][indexPath.item]; } // === BMLongPressDragCellCollectionView 的核心方法 ↓ -- (NSArray *)dataSourceWithDragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView { +- (NSArray *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView { return self.dataSourceArray; } -- (void)dragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(nullable NSArray *)newDataArray { + +- (void)dragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(NSArray *> *)newDataArray { self.dataSourceArray = [newDataArray mutableCopy]; } diff --git a/Example/BMLongPressDragCellCollectionView/Demo/Classes/AliPay/Alipay2/Controller/BMAlipay2VC.m b/Example/BMLongPressDragCellCollectionView/Demo/Classes/AliPay/Alipay2/Controller/BMAlipay2VC.m index 4158a680..1bec5781 100644 --- a/Example/BMLongPressDragCellCollectionView/Demo/Classes/AliPay/Alipay2/Controller/BMAlipay2VC.m +++ b/Example/BMLongPressDragCellCollectionView/Demo/Classes/AliPay/Alipay2/Controller/BMAlipay2VC.m @@ -108,7 +108,7 @@ - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(BMAli cell.model = self.dataSourceArray[indexPath.section][indexPath.item]; } -- (NSArray *)dataSourceWithDragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView { +- (NSArray *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView { return self.dataSourceArray; } diff --git a/Example/BMLongPressDragCellCollectionView/Demo/Classes/QQ/Controller/BMQQImageVC.m b/Example/BMLongPressDragCellCollectionView/Demo/Classes/QQ/Controller/BMQQImageVC.m index 0cd5c202..23084e03 100644 --- a/Example/BMLongPressDragCellCollectionView/Demo/Classes/QQ/Controller/BMQQImageVC.m +++ b/Example/BMLongPressDragCellCollectionView/Demo/Classes/QQ/Controller/BMQQImageVC.m @@ -14,7 +14,7 @@ @interface BMQQImageVC () *dataSourceArray; +@property (strong, nonatomic) NSMutableArray *> *dataSourceArray; @end @@ -44,25 +44,30 @@ - (void)viewDidLoad { [self.imageCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass(BMImageCell.class) bundle:nil] forCellWithReuseIdentifier:imageIdentifier]; } -- (NSMutableArray *)dataSourceArray { +- (NSMutableArray *> *)dataSourceArray { if (!_dataSourceArray) { - _dataSourceArray = [@[] mutableCopy]; + NSMutableArray *arr = [@[] mutableCopy]; int sec = 193; while (--sec > 0) { CGFloat width = arc4random_uniform(60) + 40; - [_dataSourceArray addObject:@{@"icon" : [NSString stringWithFormat:@"%03d.png", sec], @"size" : [NSValue valueWithCGSize:CGSizeMake(width, width)]}]; + [arr addObject:@{@"icon" : [NSString stringWithFormat:@"%03d.png", sec], @"size" : [NSValue valueWithCGSize:CGSizeMake(width, width)]}]; } + _dataSourceArray = @[arr].mutableCopy; } return _dataSourceArray; } +- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { + return self.dataSourceArray.count; +} + - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { - return [self.dataSourceArray count]; + return self.dataSourceArray[section].count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ BMImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:imageIdentifier forIndexPath:indexPath]; - UIImage *image = [UIImage imageNamed:self.dataSourceArray[indexPath.row][@"icon"]]; + UIImage *image = [UIImage imageNamed:self.dataSourceArray[indexPath.section][indexPath.item][@"icon"]]; if (!image) { image = [UIImage imageNamed:@"001.png"]; } @@ -70,15 +75,15 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell return cell; } -- (NSArray *)dataSourceWithDragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView { +- (NSArray *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView { return self.dataSourceArray; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { - return [self.dataSourceArray[indexPath.row][@"size"] CGSizeValue]; + return [self.dataSourceArray[indexPath.section][indexPath.item][@"size"] CGSizeValue]; } -- (void)dragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(NSArray *)newDataArray { +- (void)dragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(NSArray *> *)newDataArray { self.dataSourceArray = [newDataArray mutableCopy]; } diff --git a/Example/BMLongPressDragCellCollectionView/Demo/Classes/TestSize/Controller/BMTestSizeVC.m b/Example/BMLongPressDragCellCollectionView/Demo/Classes/TestSize/Controller/BMTestSizeVC.m index 598a0f09..71121835 100644 --- a/Example/BMLongPressDragCellCollectionView/Demo/Classes/TestSize/Controller/BMTestSizeVC.m +++ b/Example/BMLongPressDragCellCollectionView/Demo/Classes/TestSize/Controller/BMTestSizeVC.m @@ -78,11 +78,12 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell return cell; } -- (NSArray *)dataSourceWithDragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView { +- (NSArray *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView { return self.dataSource; } -- (void)dragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(NSArray *)newDataArray { + +- (void)dragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(NSArray *> *)newDataArray { self.dataSource = [newDataArray mutableCopy]; } diff --git a/Example/BMLongPressDragCellCollectionView/Demo/Classes/TouTiao/Edit/Controller/BMChannelEditVC.m b/Example/BMLongPressDragCellCollectionView/Demo/Classes/TouTiao/Edit/Controller/BMChannelEditVC.m index 098f305f..16234dc8 100644 --- a/Example/BMLongPressDragCellCollectionView/Demo/Classes/TouTiao/Edit/Controller/BMChannelEditVC.m +++ b/Example/BMLongPressDragCellCollectionView/Demo/Classes/TouTiao/Edit/Controller/BMChannelEditVC.m @@ -170,7 +170,7 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa #pragma mark - BMLongPressDragCellCollectionViewDataSource -- (NSArray *)dataSourceWithDragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView { +- (NSArray *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView { return self.channelModelArray; } @@ -214,7 +214,7 @@ - (BOOL)dragCellCollectionViewShouldBeginExchange:(BMLongPressDragCellCollection } /// Cell 有交换时调用 -- (void)dragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(NSArray *)newDataArray { +- (void)dragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(NSArray *> *)newDataArray { self.channelModelArray = [newDataArray mutableCopy]; } diff --git a/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoCollectionViewCell.swift b/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoCollectionViewCell.swift index f7056248..5233f232 100644 --- a/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoCollectionViewCell.swift +++ b/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoCollectionViewCell.swift @@ -25,13 +25,13 @@ class SwiftDemoCollectionViewCell: UICollectionViewCell { override init(frame: CGRect) { super.init(frame: .zero) contentView.addSubview(descLabel) - descLabel.backgroundColor = .darkGray - descLabel.layer.cornerRadius = 20 - descLabel.layer.masksToBounds = true + descLabel.backgroundColor = .init(red: 0, green: 0, blue: 0, alpha: 0.2) descLabel.textAlignment = .center descLabel.snp.makeConstraints { (make) in - make.edges.equalTo(10) + make.edges.equalToSuperview().inset(10) } + descLabel.layer.cornerRadius = 15 + descLabel.layer.masksToBounds = true } required init?(coder: NSCoder) { diff --git a/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoVC.swift b/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoVC.swift index 2bf71f50..fa13c27b 100644 --- a/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoVC.swift +++ b/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoVC.swift @@ -8,46 +8,58 @@ import UIKit + + +// --------------------------------------------------------- +// MARK: - SwiftDemoVC +// --------------------------------------------------------- class SwiftDemoVC: UIViewController { + @IBOutlet weak var collectionView: BMLongPressDragCellCollectionView! - lazy var dataSourceArray: [Int8] = { - var arr = [Int8]() - for i in 0...10 { - arr.append(Int8(i)) - } - return arr - }() + var dataSourceArray = [(1...10).map { $0 }] } -extension SwiftDemoVC : BMLongPressDragCellCollectionViewDelegate, BMLongPressDragCellCollectionViewDataSource { + + +// --------------------------------------------------------- +// MARK: - BMLongPressDragCellCollectionViewDataSource +// --------------------------------------------------------- + +extension SwiftDemoVC : BMLongPressDragCellCollectionViewDataSource { - func dragCellCollectionView(_ dragCellCollectionView: BMLongPressDragCellCollectionView, newDataArrayAfterMove newDataArray: [Any]?) { - if let arr = newDataArray as? [Int8] { - dataSourceArray = arr - } + func dataSource(with dragCellCollectionView: BMLongPressDragCellCollectionView) -> [[Any]]? { + dataSourceArray } - func dataSource(with dragCellCollectionView: BMLongPressDragCellCollectionView) -> [Any]? { - return dataSourceArray + func numberOfSections(in collectionView: UICollectionView) -> Int { + dataSourceArray.count } - + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - dataSourceArray.count + dataSourceArray[section].count + } +} + + + +// --------------------------------------------------------- +// MARK: - BMLongPressDragCellCollectionViewDelegate +// --------------------------------------------------------- + +extension SwiftDemoVC : BMLongPressDragCellCollectionViewDelegate { + + func dragCellCollectionView(_ dragCellCollectionView: BMLongPressDragCellCollectionView, newDataArrayAfterMove newDataArray: [[Any]]?) { + if let arr = newDataArray as? [[Int]] { + dataSourceArray = arr + } } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let num = dataSourceArray[indexPath.item] - if num%2 == 0 { - let cell = SwiftDemoCollectionViewCell.bm_collectionViewCellFromAlloc(with: collectionView, for: indexPath) - if let cell1 = cell { - cell1.desc = String(dataSourceArray[indexPath.item]) - return cell1 - } - } else { - let cell = SwiftDemoXibCollectionViewCell.bm_collectionViewCellFromNib(with: collectionView, for: indexPath) - if let cell1 = cell { - return cell1 - } + let cell = SwiftDemoCollectionViewCell.bm_collectionViewCellFromAlloc(with: collectionView, for: indexPath) + if let cell1 = cell { + let num = dataSourceArray[indexPath.section][indexPath.item] + cell1.desc = "\(num)" + return cell1 } return UICollectionViewCell() } diff --git a/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoXibCollectionViewCell.swift b/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoXibCollectionViewCell.swift deleted file mode 100644 index 6e231702..00000000 --- a/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoXibCollectionViewCell.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// SwiftDemoXibCollectionViewCell.swift -// BMLongPressDragCellCollectionView_Example -// -// Created by liangdahong on 2020/7/1. -// Copyright © 2020 ios@liangdahong.com. All rights reserved. -// - -import UIKit - -class SwiftDemoXibCollectionViewCell: UICollectionViewCell { - -} diff --git a/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoXibCollectionViewCell.xib b/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoXibCollectionViewCell.xib deleted file mode 100644 index 4deb1255..00000000 --- a/Example/BMLongPressDragCellCollectionView/Demo/Swift/SwiftDemoXibCollectionViewCell.xib +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/README.md b/README.md index cbc52661..f8d48556 100755 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ pod install 如下: ``` -- (NSArray *)dataSourceWithDragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView { +- (NSArray *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView { return self.dataSourceArray; } ```