何时是旋转的适当时刻以更改UICollectionView的布局参数 [英] When is the appropriate moment in rotation to change the Layout parameters of a UICollectionView
问题描述
希望一个相对较新的 UIKit
控件的简单问题
Hopefully a simple question for a relatively new UIKit
control
我有一个 UICollectionView
有一个 viewLayout
,其单行单元格是 UICollectionView $ c $的确切高度c>纵向模式下的边界
I have a UICollectionView
that has a viewLayout
with a single row of cells that are the exact height of the UICollectionView
bounds in Portrait mode
因此,当iPad被翻转到横向模式时,该行变得比屏幕本身更高,此时布局(几乎)静默失败并抱怨行高于边界。
Therefore, when the iPad is flipped to Landscape mode, that row becomes taller than the screen itself, at which point the layout (almost) silently fails and complains that the row is taller than the bounds.
操纵viewLayout特征的理想方法是什么,特别是因为它涉及响应旋转 ViewController
?
What is the ideal way to manipulate the characteristics of the viewLayout, particularly as it relates to responding to rotation in a ViewController
?
推荐答案
我正在研究类似的问题。
I'm working on a similar problem.
目前,我的UICollectionViewController有两个UICollectionViewFlowLayout实例变量,每个变量都有适当的portait或landscape插图。
Currently, my UICollectionViewController has two instance variables of UICollectionViewFlowLayout, each with the appropriate insets for portait or landscape.
在轮换时,我这样做:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration{
if (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) {
[_itemCollection setCollectionViewLayout:_portraitLayout];
[_itemCollection reloadData];
} else {
[_itemCollection setCollectionViewLayout:_landscapeLayout];
[_itemCollection reloadData];
}
}
我遇到的唯一问题是它随机地在setCollectionViewLayout上使用exc_bad_access随机崩溃。
The only problem that I'm having is that it randomly crashes with exc_bad_access on setCollectionViewLayout randomly.
上述内容可能对您有用。我不确定这是否是正确的做事方式。我最近才开始使用UICollectionViews。
Something like the above might work for you. I'm not sure if this is the right way to do things. I have only recently started using UICollectionViews.
这篇关于何时是旋转的适当时刻以更改UICollectionView的布局参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!