czl0325 / ZLCollectionView

为应对类似淘宝首页,京东首页,国美首页等复杂布局而写的Collectionview。基于UICollectionView实现,目前支持标签布局,列布局,百分比布局,定位布局,填充式布局,瀑布流布局等。支持纵向布局和横向布局,可以根据不同的section设置不同的布局,支持拖动cell,头部悬浮,设置section背景色和自定义section背景view,向自定义背景view传递自定义方法。功能强大,超过Android的recyclerview,实现了电影选座等高难度的布局。
MIT License
1.16k stars 166 forks source link

cell高度差比较小的时候 minimumLineSpacing 出现异常 #32

Closed cxz31415 closed 3 years ago

cxz31415 commented 4 years ago

新建一个项目,把我提供的代码复制进去运行,就会出现如图这种情况 E43DAEC65AB6C71D58D2349EE925DFA3

// // ViewController.m // ZLCollectionTest // // Created by cxz31415 on 2020/8/17. // Copyright © 2020 cxz31415. All rights reserved. //

import "ViewController.h"

import "ZLCollectionViewVerticalLayout.h"

@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,ZLCollectionViewBaseFlowLayoutDelegate> @property (copy, nonatomic) NSString collectionViewCellName; @property (strong, nonatomic) UICollectionView collectionView; @property (strong, nonatomic) NSMutableArray *dataArrM; @end

@implementation ViewController

define MainScreen [UIScreen mainScreen]

define MainScreenScale MainScreen.scale

define ScreenF [MainScreen bounds]

define ScreenS ScreenF.size

define ScreenW ScreenS.width

-(void)initCollectionView{ _collectionViewCellName = @"UICollectionViewCell";

ZLCollectionViewVerticalLayout *layout = [[ZLCollectionViewVerticalLayout alloc] init];
//水平方向滚动
//layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.delegate = self;
layout.minimumLineSpacing = 20;
layout.minimumInteritemSpacing = 10;

_collectionView = [[UICollectionView alloc]initWithFrame:ScreenF collectionViewLayout:layout];
[_collectionView registerClass:[UICollectionViewCell class]forCellWithReuseIdentifier:_collectionViewCellName];

_collectionView.delegate = self;
_collectionView.dataSource = self;
//内容较少时也有垂直方向反弹效果(用于上下拉加载数据)
_collectionView.alwaysBounceVertical = YES;
_collectionView.backgroundColor = UIColor.clearColor;

// _collectionView.scrollEnabled = NO; [self.view addSubview:_collectionView]; }

pragma - mark - collection view datasoure

-(CGSize)collectionView:(UICollectionView )collectionView layout:(UICollectionViewLayout )collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath )indexPath{ NSNumber number = _dataArrM[indexPath.item]; return CGSizeMake((ScreenW - 30) * 0.5, number.floatValue); }

-(UIEdgeInsets)collectionView:(UICollectionView )collectionView layout:(UICollectionViewLayout )collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ return UIEdgeInsetsMake(0, 10, 0, 10); }

@end

czl0325 commented 4 years ago

麻烦demo压缩后发我邮箱295183917@qq.com

cxz31415 commented 4 years ago

邮件已发送

czl0325 commented 4 years ago

你先指定为瀑布流布局,2列,填充式布局minimumLineSpacing 大于 item高度会有问题,还得再修改下

cxz31415 commented 4 years ago

不是的,这个只是用来测试的demo,我为了省事才这么写,我自己的项目里面用到了你的库,cell里面有图片和文字,高度都是超过minimumLineSpacing很多的,有的时候比如第一个cell高度为110,第二个为114,相差很小,就会出现这种情况

你可以把我发的demo里面那行填写高度数组的代码改成后面那样,高度都比minimumLineSpacing大,但是minimumLineSpacing照样有问题,不过我只是想要实现瀑布流而已,用你说的办法确实没问题了,感谢告知。 [_dataArrM addObject:@(arc4random_uniform(4) * 20 + 10)]; [_dataArrM addObject:@(arc4random_uniform(10) + 100)];

CB754EC4-75EE-49F1-8C94-0DB7523EC648

czl0325 commented 4 years ago

发你邮箱的包你替换测试下

cxz31415 commented 4 years ago

这个正常了

czl0325 commented 4 years ago

用填充式布局正常吗?

------------------ 原始邮件 ------------------ 发件人: "czl0325/ZLCollectionView" <notifications@github.com>; 发送时间: 2020年8月18日(星期二) 下午5:16 收件人: "czl0325/ZLCollectionView"<ZLCollectionView@noreply.github.com>; 抄送: "陈昭良"<295183917@qq.com>;"Comment"<comment@noreply.github.com>; 主题: Re: [czl0325/ZLCollectionView] cell高度差比较小的时候 minimumLineSpacing 出现异常 (#32)

这个正常了

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

cxz31415 commented 4 years ago

用填充式布局正常了。

cxz31415 commented 4 years ago

又有问题啦,这个填写小数的时候又不正常了(填充式布局),还是用我发给你的那个demo测试 layout.minimumLineSpacing = 15.5; layout.minimumInteritemSpacing = 10.5; 要不加个向下取整?

czl0325 commented 4 years ago

minimumLineSpacing 不能大于item的宽高,你是不是超过了?

cxz31415 commented 4 years ago

就是单纯改成小数而已,我之前不是发了demo给你吗?你试下就知道了

cxz31415 commented 4 years ago

你是不是邮件删了?我重新发给你吧,你就改这行代码 layout.minimumLineSpacing = 15.1; layout.minimumLineSpacing = 15; 这个值设置成15.1和15完全是两个效果

czl0325 commented 4 years ago

提交1.4.3版本了