0

したがって、私はePubフレームワークの一部であるアプリケーションで作業しています。このアプリは閲覧者をそのビューに埋め込み、ユーザーがスワイプでズームとページをスクロールできるようにします。 Imは、ePubのリストがepubの表紙画像を表示するセルとしてcollectionviewに来るように変更しようとしています。私はflowlayoutのためのセルを作成することができますし、フレームの境界を使用して私はセルを作成することができますが、私はしようとすると、サイズと位置に調整しないでください肖像画から風景に回転する。細胞のための私のコードはこれです:回転時にUICollectionViewFlowLayoutセルを調整する

//Set Collection View Cell Size and Orientation 
-(CGSize) 
    collectionView:(UICollectionView *) collectionView 
    layout:(UICollectionViewLayout*)collectionViewLayout 
    sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ 

//Set Landscape size of cells 
if(UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){ 
    CGFloat cellWidth = [[UIScreen mainScreen] bounds].size.width; 
    CGFloat cellHeigt = [[UIScreen mainScreen] bounds].size.height-350; 
    NSLog(@"Is Landscape"); 
    return CGSizeMake(cellWidth, cellHeigt); 
} 
//Set Potrait size of cells 
else{ 
    NSLog(@"Is Portrait"); 
    CGFloat cellWidth = [[UIScreen mainScreen] bounds].size.width-80; 
    CGFloat cellHeigt = [[UIScreen mainScreen] bounds].size.height-240; 
    return CGSizeMake(cellWidth, cellHeigt); 
} 
} 

と私はそれらを配置するために、このコードを使用します。

//Collection View Cell Position 
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { 

if(UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){ 
    return UIEdgeInsetsMake(0,10,0,20); // top, left, bottom, right 
} 
else{ 
    return UIEdgeInsetsMake(0,20,0,20); // top, left, bottom, right 
} 
} 

私は細胞のトップ境界がフレームの上に行くデバイスを回転させたとき。

どうすればフレームを動的に更新できますか?

答えて

0

ローテーション中にコレクションをリフレッシュする必要があります。次のコードを試してください:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    [yourCollectionview performBatchUpdates:nil completion:nil]; 
} 
+0

ありがとうございます。どのように私のビューコントローラを参照するのですか?グローバルな宣言はありません。質問を編集して、リストコントローラ全体のコードを記述する必要がありますか? –

+0

はい、あなたのviewcontrollerには、collectionViewのデータソースメソッドを置いてあります。 – KKRocks

+0

ありがとう私は今このショットを与えるよ –

関連する問題