背景
我正在拍摄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 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的值,其细节类似于通常的框架。
实际结果-
上述警告。
我想要调试的东西-
collectionView单元格的布局在iOS 9中是自动变化的(在旋转后一个在下),而iOS 8中的其他布局(水平视图)是完美的。
提前谢谢。
发布于 2015-11-20 05:42:03
备选解决方案
基于您更新的关于想要处理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];
}];
}或
在旋转视图方法中,可以在invalidateLayout上调用UICollectionView。
或
您可以尝试将UIImageView放入集合视图单元格并使用自动布局。然后将视图控制器的快照设置为UIImageView上的图像。
80+关于SO的其他问题 (可能提供一些见解)
警告
关于你所看到的警告。您所说的不重要的代码很可能是为UIModalPresentationStyle类型的属性分配无效值造成的(如果没有更重要的代码,就很难达到更高的精度)。此外,您所展示的代码在使用管道( autoresizingMask )时也有一个小问题。这些代码可以编码为[UIViewAutoresizingFlexibleWidth, UIViewAutoresizingFlexibleHeight]。
https://stackoverflow.com/questions/33735830
复制相似问题