简体   繁体   English

当滚动方向为水平时,从左到右填充UICollectionView

[英]Populate UICollectionView from left to right when scrolling direction is horizontal

When scrolling direction is horizontal cells are added in UICollectionView from top to bottom 当滚动方向为水平时,在UICollectionView中从上到下添加单元格 在此输入图像描述

For scrolling direction = vertical, they are added from left to right. 对于滚动方向=垂直,它们是从左到右添加的。 在此输入图像描述

The question is, if there is any way to add cells from left to right when scrolling direction is horizontal ? 问题是,当滚动方向是水平时,是否有任何方法可以从左到右添加单元格?

The order is automatically generated by the scroll direction, which is set by default. 订单由滚动方向自动生成,默认设置。 数字

What you can do is to add a custom layout for the UICollectionView by using the layoutAttributesForItemAtIndexPath method to set a frame for each individual cell. 您可以做的是通过使用layoutAttributesForItemAtIndexPath方法为每个单独的单元格设置框架,为UICollectionView添加自定义布局。

-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewLayoutAttributes* attr = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];

    CGRect cellFrame = CGRectMake(/* calculate your origin x */,
                                  /* calculate your origin y */,
                                  /* calculate your width */,
                                  /* calculate your height */);
    attr.frame = cellFrame;

    return attr;
}

More details can be found here 更多细节可以在这里找到

You need to use UICollectionViewFlowLayout and set the scrollDirection property to 您需要使用UICollectionViewFlowLayout并将scrollDirection属性设置为

flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

Default setting is is vertical (top to bottom) 默认设置为垂直(从上到下)

每个集合视图都有布局属性,允许您更改滚动方向。您可以这样做:

collectionView.collectionViewLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

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

相关问题 UICollectionView:1行水平滚动(从右到左),带有自定义动画,用于从右到右的新单元格 - UICollectionView: 1 row horizontal scrolling (right to left) with custom animation for new cell coming from right 如何防止在水平滚动方向上向左向右滚动集合视图? - How to prevent scrolling left to right of collection view in horizontal scroll direction? 对两个项目使用水平滚动时(对于RTL),将UICollectionView右对齐 - Right aligned UICollectionView when using Horizontal scrolling with two items (for RTL) 如何自定义 UICollectionView 在水平方向左对齐 - How to custom UICollectionView to left align in horizontal direction UICollectionView水平滚动,数据从左到右流动 - UICollectionView scroll horizontal with data flowing from left to right 我的uiscrollview在从左到右和从右到左的水平滚动中无法正常工作 - My uiscrollview is not working properly on horizontal scrolling from left to right and right to left UICollectionView中的单边方向滚动? - Unilateral Direction Scrolling in a UICollectionView? 渐变方向从左到右 - gradient direction from left to right 左右滑动手势可水平滚动tableview - Horizontal scrolling of tableview with swipe gesture left and right 在UICollectionView中禁用水平滚动 - Disable horizontal scrolling in UICollectionView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM