iOS:如何更改UICollectionViewCell的方向?

时间:2012-10-09 21:12:29

标签: ios orientation ios6 uicollectionview uicollectionviewcell

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

在Interface Builder或我的代码中,我应该做些什么吗?我尝试使用-(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); } ,但这没有用。如果其他人之前遇到过这种情况,我将非常感激!非常感谢!

以下是一些参考代码:

{{1}}

1 个答案:

答案 0 :(得分:4)

如果其他人遇到这个问题,我就是这样解决的。

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

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

如果有任何人有任何疑问,请与我联系。希望它有所帮助!