我有一个
UICollectionViewController
,当用户将其iPad旋转以使其处于横向方向时,我会加载它。我的问题是,我的 UICollectionViewCells
仍然像在纵向方向下一样加载。我在Interface Builder中将 UICollectionViewController
设置为横向,并且我正在使用我称之为 CollectionViewCell
的自定义单元格类。每个单元格只包含图像和标签。
在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"];
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);
}