iOS:如何更改UICollectionViewCell的方向?

iOS:如何更改UICollectionViewCell的方向?,ios,orientation,ios6,uicollectionview,uicollectionviewcell,Ios,Orientation,Ios6,Uicollectionview,Uicollectionviewcell,我有一个UICollectionViewController,当用户转动iPad时,我会加载它,以便将其置于横向。我遇到的问题是,我的UICollectionViewCells仍在加载,就好像它是纵向的一样。我将UICollectionViewController设置为Interface Builder内部的横向,并使用一个我称之为CollectionViewCell的自定义单元格类。每个单元格只包含一个图像和一个标签 我是否应该在Interface Builder或代码中执行某些操作?我尝试使

我有一个
UICollectionViewController
,当用户转动iPad时,我会加载它,以便将其置于横向。我遇到的问题是,我的
UICollectionViewCell
s仍在加载,就好像它是纵向的一样。我将
UICollectionViewController
设置为Interface Builder内部的横向,并使用一个我称之为
CollectionViewCell
的自定义单元格类。每个单元格只包含一个图像和一个标签

我是否应该在Interface Builder或代码中执行某些操作?我尝试使用
cGraffineTransformationMakeRotation
,但没有任何帮助。如果其他人以前遇到过这种情况,我将不胜感激!非常感谢

以下是一些代码供参考:

-(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"];
    cell.name.text=@"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);

}

如果其他人也有这个问题,下面是我如何解决的

我最初不允许自动旋转,而是使用
NSNotificationCenter
注册
orientationChanged
通知。这非常有效,只是它阻止了我的第二个视图意识到它需要以横向模式加载

因此,我为我的主视图嵌入的
选项卡栏
创建了一个类,并为该类中的
shouldAutoRotate
方法以及除我希望以横向模式加载的视图之外的所有其他视图返回
NO
。我仍然在主视图的控制器中使用
orientationChanged
通知,因为它嵌入在
tabBar
中。但我只是在返回主视图时使用自动旋转


如果有人有任何问题,请告诉我。希望有帮助

我使用的是自定义UICollectionView,每个单元格都有动态高度。但当我旋转时,我的单元格不会通过columnWidthForCollectionView方法更改宽度,也不会通过maximumNumberOfColumnsForCollectionView方法更改列数。我正在动态计算我的列宽。通过-(CGFloat)getCollumnWidth{CGFloat width=(self.view.frame.size.width-(kCollectionCellBorderRight*3))/2;返回宽度;}这在iPhone和iPad中都会发生。