简体   繁体   English

UICollectionView第一个单元格未正确对齐

[英]UICollectionView first cell not aligned properly

In my app, I have a UICollectionView inside a UITableView that is showing cells to select a day. 在我的应用程序中,我有一个UITableView内的UICollectionView,该UICollectionView显示用于选择一天的单元格。

I had a weird issue where sometimes, the cells would be centered correctly, and sometimes it wouldn't, to the point where part of the first cell is cut off in the view. 我有一个奇怪的问题,有时单元会正确居中,有时却不能正确居中,以至于视图中第一个单元的一部分被切除。

Normal 正常 在此处输入图片说明

Not Aligned 不对齐 在此处输入图片说明

What is going on? 到底是怎么回事? I've adjusted the UIEdgeInsets, but it doesn't seem to make an effect. 我已经调整了UIEdgeInsets,但似乎没有效果。

I have found out that my issue was fixed when I removed this line of code for the UICollectionViewFlowLayout of the UICollectionView 我发现当我删除UICollectionView的UICollectionViewFlowLayout的这一行代码时,我的问题已修复

For a defined 对于定义

UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];

Remove this 删除这个

layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM