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