2017-04-03 8 views
2

私はカメラとギャラリーを使って画像を撮ってコレクションビューに追加しています。画像をコレクションビューに水平方向に追加したいので、画像を配列に追加してコレクションフレームを変更してコレクションビューの幅を増やします私はそれの高さを増加させるように水平にスクロールされていないので、それを行う方法は何ですか?あなたは写真の数に基づいて幅を設定しているcollectionviewをスクロールする方法は?

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

'[yourFlowLayout setScrollDir :UICollectionViewScrollDirectionHorizo​​ntal]; 'これを使用してください –

+0

私はストーリーボードで方向を設定しました。 – LanWanMan

+0

1. collectionviewのframe.widthを変更する必要はありません。親ビューに最大で固定します。 2.ストーリーボードから行うことができるコレクションビュー内で調整するセルサイズを調整します。 3.ストーリーボードを使用してアイテムを追加して、セルが正しく水平に整列しているかどうかをテストできます。デザインビューでの表示方法のみを表示できます。 – iphonic

答えて

2

ビューでのコード行を試してみてくださいあなたは、単にプロパティインスペクタ

enter image description here

を通してそれを設定することができますそれとも、

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; 
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; 
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]; 
0

は、ここに私のコードです。妥当な値に設定する必要があります。

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

を試してみて、水平にコレクションビューのscrooll方向を設定します。

0

をプログラム的に設定することができなかった負荷

[yourCollectionView setScrollDirection:UICollectionViewScrollDirectionVertical]; 
関連する問題