如何将collectionview水平滚动?

时间:2017-04-03 06:15:31

标签: ios objective-c iphone uicollectionview

我正在使用相机和图库来拍摄图像并将其添加到集合视图,我想将图像添加到集合视图到水平方向,所以我将图像添加到数组并更改集合框架以增加集合视图宽度增加,但集合不会滚动到水平,因为我增加它的高度,那么有什么方法呢?





这是我的代码:


& #xA;
  UIImage * image = [info valueForKey:UIImagePickerControllerOriginalImage];
 [arrayPictures addObject:image];
 _collPic.frame = CGRectMake(0,_collPic.frame.origin.y ,arrayPictures.count * 76,76);
 [_ collPic reloadData];
  



4 个答案:

答案 0 :(得分:3)

您只需通过属性检查器

进行设置即可

enter image description here

或者您可以使用

以编程方式设置
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];

答案 1 :(得分:0)

UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init ];
layout.minimumInteritemSpacing = 5;
layout.minimumLineSpacing = 6;
layout.itemSize = CGSizeMake(55, 55);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
blendEffectCollectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 95, 320, 60) collectionViewLayout:layout];
[blendEffectCollectionView setDataSource:self];
[blendEffectCollectionView setDelegate:self];

[blendEffectCollectionView registerClass:[BlendModeCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
[blendEffectCollectionView setBackgroundColor:[UIColor clearColor]];

[self.view addSubview:blendEffectCollectionView];

答案 2 :(得分:0)

您正在根据照片数量设置宽度。它应该设置为合理的值。

尝试

_collPic.frame = CGRectMake(0, _collPic.frame.origin.y, self.view.frame.width, 76);

并将集合视图的scrooll方向设置为水平。

答案 3 :(得分:0)

在视图中尝试这行代码加载

[yourCollectionView setScrollDirection:UICollectionViewScrollDirectionVertical];