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

注意 - 我在 Xcode 6.4 上使用iOS8运行的代码相同,它运行时没有出现故障/警告。此外,我能够在调试区域中找到变量的值。

更多信息 :-

断点 -我把它放在下面的方法中

- (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 的值。

实际结果 -

上面提到的警告。

我正在尝试调试的内容-

在 iOS 9 中,collectionView 单元格的布局会自动更改(在旋转后出现在另一个下方),而在 iOS 8 中的其他布局(水平视图)是完美的。

提前致谢。

4

1 回答 1

3

替代解决方案

根据您关于想要处理 UICollectionView 旋转的更新评论。您是否尝试将以下方法添加到包含 Collection View 的 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。

或者

您可以尝试将 UIImageView 放入集合视图单元格并使用自动布局。然后将视图控制器的快照设置为 UIImageView 上的图像。

来自 Apple 的示例 CollectionView 项目

关于 SO 的 80 多个其他问题(可能提供一些见解)

警告

关于您看到的警告。您所说的代码不重要可能是由于将无效值分配给 UIModalPresentationStyle 类型的属性(如果没有更重要的代码,更精确是困难的)。此外,您显示的代码还有一个小问题,即您在 autoresizingMask 中使用管道 (|)。这些可以编码为[UIViewAutoresizingFlexibleWidth, UIViewAutoresizingFlexibleHeight]

于 2015-11-20T05:42:03.433 回答