5

UICollectionViewControllerユーザーがiPadを横向きにするためにiPadを回転させたときにロードする があります。私が抱えている問題は、私UICollectionViewCellの s がまだ縦向きであるかのようにロードされていることです。UICollectionViewControllerInterface Builder 内で を横向きに設定し、と呼んだカスタム セル クラスを使用してい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);

}
4

1 に答える 1

4

他の誰かがこの問題を抱えている場合に備えて、これが私が解決した方法です。

最初は自動回転を許可していませんでしたが、代わりに をorientationChanged使用して通知を登録していNSNotificationCenterました。これは、2 番目のビューがランドスケープ モードでロードする必要があることを認識するのを妨げていたことを除いて、うまく機能しました。

その代わりにtabBar、メイン ビューが埋め込まれているのクラスを作成し、そのクラスNOshouldAutoRotateメソッドと、ランドスケープ モードでロードするビューを除く他のすべてのビューに戻ります。orientationChangedに埋め込まれているため、メインビューのコントローラーで通知をまだ使用していtabBarます。しかし、メイン ビューに戻るときに自動回転を使用しているだけです。

ご不明な点がございましたら、お気軽にお問い合わせください。それが役に立てば幸い!

于 2012-10-10T17:34:42.857 に答える