2012-10-09 38 views
5

我有一個UICollectionViewController,當用戶轉動他們的iPad以便將其放入橫向時,我會加載它。我遇到的問題是我的UICollectionViewCell仍在加載,就好像它是縱向的。我將UICollectionViewController設置爲在界面構建器內景觀,我使用的是我稱之爲CollectionViewCell的自定義單元類。每個單元格只包含一個圖像和一個標籤。iOS:如何更改UICollectionViewCell的方向?

有什麼我應該在界面生成器或在我的代碼?我嘗試使用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); 

} 

回答

4

如果任何人有過這樣的問題,這裏是我如何解決它。

我最初不允許自動旋轉,而只是使用NSNotificationCenter註冊orientationChanged通知。這很好,除了它阻止我的第二個視圖意識到它需要以橫向模式加載。

所以不是說,我已經創建了我的主視圖嵌入在tabBar一類,我在那類和除每隔一個視圖返回NOshouldAutoRotate方法,我想在橫向模式下加載。我仍然在我的主視圖的控制器中使用orientationChanged通知,因爲它嵌入在tabBar中。但是當我回到主視圖時我只是使用自動旋轉。

如果有人有任何問題,請告訴我。希望能幫助到你!

+0

我在每個單元格中使用具有動態高度的自定義UICollectionView。但是當我旋轉時,我的單元格不通過columnWidthForCollectionView方法和列數通過maximumNumberOfColumnsForCollectionView方法更改寬度。我正在動態計算我的列寬。通過 - (CGFloat)getCollumnWidth {CGFloat width =(self.view.frame.size.width-(kCollectionCellBorderRight * 3))/ 2; 返回寬度; } iPhone和iPad都出現這種情況。 – Xeieshan