背景
我正在截取 viewController 的屏幕截图并将其呈现在 collectionViewCell 中。 collectionViewCell 的布局是水平的,但是当我选择一个 View 然后旋转设备然后返回到 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 的值与往常一样具有 frame 等细节。
实际结果-
上面提到的警告。
我正在尝试调试什么 -
在 iOS 9 中,collectionView 单元格的布局会自动更改(旋转后一个在另一个下方),而 iOS 8 布局(水平 View )中的其他布局是完美的。
提前致谢。
最佳答案
替代方案
基于您关于想要处理 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];
}];
}
或
在您的旋转 View 方法中,您可以在 UICollectionView 上调用 invalidateLayout。
或
您可以尝试将 UIImageView 放入 Collection View 单元格中并使用自动布局。然后将 View Controller 的快照设置为 UIImageView 上的图像。
Sample CollectionView Project From Apple
80+ Other Questions on SO (可能会提供一些见解)
警告
关于您看到的警告。您所说的代码不重要可能是由于为 UIModalPresentationStyle 类型的属性分配了无效值引起的(没有更重要的代码就很难更精确)。此外,您显示的代码还有一个小问题,即您在 autoresizingMask 中使用管道 (|)。这些可以编码为 [UIViewAutoresizingFlexibleWidth, UIViewAutoresizingFlexibleHeight]
。
关于ios - 调试时遇到警告问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33735830/