iPad:加载时和旋转后的奇怪帧



>我有动态大小的标签和表格视图行高。有些东西似乎不起作用。我以cellForRowAtIndexPath:记录标签的宽度。

Loading in Portrait --> 595
Rotate to Landscape --> 851
Rotate to Portrait  --> 595

看起来还行。但

Loading in Landscape --> 595
Rotate to Portrait   --> 595
Rotate to Landscape  --> 851

事实上,在横向模式下加载视图时,我的视图标签和单元格无法正确呈现。

有什么想法吗?

编辑:

当我旋转时,我只需在didRotateFromInterfaceOrientation:中调用表视图上的reloadData。这就像一个魅力。

我没有在任何地方更改标签的宽度,只是更改高度。(当然,宽度对于计算高度很重要,但我不会更改宽度。

log 语句在 cellForRowAtIndexPath末尾,总是heightForRowAtIndexPath 之后调用,所以之后没有更多的更改。

编辑2

有问题的标签是动态创建的。我现在切换到为每个方向使用不同的框架:

// in cellForRowAtIndexPath
BOLL landscape = UIInterfaceOrientationIsLandscape(
   [[UIApplication sharedApplication] statusBarOrientation]);
//...
textFieldFrame = CGRectMake(x, y, landscape ? 851 : 595, h); 

使用此帧初始化标签。

看起来您肯定没有检查在横向加载时会发生什么。更多的代码会为你提供一个修复:-)

解决方案:再次设置

-(void)willDisplayCellAtIndexPath:

最新更新