ユーザーがiPadを回転させて横向きにするときに読み込むUICollectionViewController
があります。私が抱えている問題は、私のUICollectionViewCell
がまだ縦向きであるかのように読み込んでいるということです。私はUICollectionViewController
をInterface Builderの中でランドスケープに設定しました。私はCollectionViewCell
というカスタムセルクラスを使用しています。各セルには、画像とラベルだけが含まれています。iOS:UICollectionViewCellの向きを変更するにはどうすればよいですか?
Interface Builderまたはコード内で行うべきことはありますか?私はCGAffineTransformationMakeRotation
を使ってみましたが、それは助けになりませんでした。これまで誰かがこれに遭遇した場合、私は非常に感謝しています!どうもありがとう!
ここで参照するためにコードのビットがあります:
-(void)viewDidLoad
{
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section
{
return listArray.count;
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"devices" forIndexPath:indexPath];
cell.statusImage.image=[UIImage imageNamed:@"Default.png"];
[email protected]"HEY !!!!!";
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(320, 420);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(50, 20, 50, 20);
}
私はすべてのセルでダイナミックな高さを持つカスタムUICollectionViewを使用しています。しかし、私が回転すると、私のセルはcolumnWidthForCollectionViewメソッドとmaximumNumberOfColumnsForCollectionViewメソッドを介して列の数を介して幅を変更していません。私は列幅を動的に計算しています。 via - (CGFloat)getCollumnWidth { CGFloat width =(self.view.frame.size.width-(kCollectionCellBorderRight * 3))/ 2; 戻り幅; } これはiPhoneとiPadの両方で発生しています。 – Xeieshan