4

バックグラウンド

viewController のスクリーンショットを撮り、collectionViewCell に表示しています。collectionViewCell のレイアウトは水平ですが、ビューを選択してデバイスを回転させてから collectionView に戻ると、レイアウトは垂直になります。

デバッグするには: コードにブレークポイントを配置し、デバッグ領域で変数の出力をチェックしようとしましたが、ここで以下の警告が表示され始めました。

**Warning:**

error: property 'modalPresentationStyle' declared with incompatible types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
error: instance method 'modalPresentationStyle' has incompatible result types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
error: property 'modalPresentationStyle' declared with incompatible types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
error: instance method 'modalPresentationStyle' has incompatible result types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
error: property 'modalPresentationStyle' declared with incompatible types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
error: instance method 'modalPresentationStyle' has incompatible result types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
note: declared here with type 'UIModalPresentationStyle'
note: instance method 'modalPresentationStyle' also declared here
note: declared here with type 'UIModalPresentationStyle'
note: declared here with type 'UIModalPresentationStyle'
note: instance method 'modalPresentationStyle' also declared here
note: declared here with type 'UIModalPresentationStyle'
note: declared here with type 'UIModalPresentationStyle'
note: instance method 'modalPresentationStyle' also declared here
note: declared here with type 'UIModalPresentationStyle'
error: 6 errors parsing expression

私は使用しています:-

  • Xcode バージョン: 7.1
  • iOS: 9.1

注 - iOS8を搭載した Xcode 6.4 で実行したのと同じコードで、不具合や警告なしで実行されています。また、デバッグ領域で変数の値を見つけることができました。

より詳しい情報 :-

ブレークポイント -以下のメソッドに入れました

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    UIViewController *viewController = (UIViewController *)_tabControllers[(NSUInteger)indexPath.row];

    /* Trying to debug above viewController in debug area */
    /* Some code is here also but of no use */

    cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    return cell;

}

デバッグ領域で起動されたコマンド -

po viewController

期待される結果 -

いつものようにフレームのような詳細を持つviewControllerの値。

実結果 -

上記の警告。

私がデバッグしようとしているもの -

collectionView セルのレイアウトは、iOS 8 のレイアウト (水平ビュー) が最適であった iOS 9 では自動的に変更されます (回転後に次々と下に表示されます)。

前もって感謝します。

4

1 に答える 1

3

代替ソリューション

UICollectionView の回転を処理したいという更新されたコメントに基づいています。コレクション ビューを含む UIViewController に次のメソッドを追加しようとしましたか?

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

    [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        [self.collectionView performBatchUpdates:^{
            [self.collectionView setCollectionViewLayout:self.collectionView.collectionViewLayout animated:YES];
        } completion:nil];
    }];
}

また

ローテーション ビュー メソッドでは、UICollectionView で invalidateLayout を呼び出すことができます。

また

コレクション View セルに UIImageView を入れて、自動レイアウトを使用することができます。次に、View Controller のスナップショットを UIImageView のイメージとして設定します。

Apple の CollectionView プロジェクトのサンプル

SO に関する 80 以上のその他の質問(洞察が得られる場合があります)

警告

表示されている警告について。重要ではないと言っているコードは、タイプ UIModalPresentationStyle のプロパティに無効な値を割り当てることが原因である可能性があります (より重要なコードがなければ、精度を高めることは困難です)。また、表示されているコードには、autoresizingMask でパイプ (|) を使用している小さな問題があります。これらは としてコーディングできます[UIViewAutoresizingFlexibleWidth, UIViewAutoresizingFlexibleHeight]

于 2015-11-20T05:42:03.433 に答える