水平滚动UITableView自动旋转界面时的BUG
在我的应用程序的一个屏幕中,我实现了水平滚动表格视图。 选择的方法是对表格视图应用 90 度旋转,然后将每个单元格旋转 -90 度。 除了自转问题外,一切都运行良好。我已经花了这一天的大半天在这上面,但到目前为止还没有运气。
tableview框架根据table的autoresizingMasks改变,就OK了。问题在于表格视图单元格不能很好地自动调整大小。
我已经成功地使用视图控制器的这一小段代码很好地调整了单元格的高度(具有平滑的动画)。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[volumesPicker beginUpdates];
[volumesPicker endUpdates];
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:currentFocusedIndex inSection:0];
[volumesPicker scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
问题出在表格视图单元格宽度上。例如:
我在设备处于横向模式时启动应用程序。表格视图渲染得很好。
我在纵向模式下旋转设备,我的单元格的宽度突然比表格更小(请记住,表格视图被旋转,因此单元格的宽度实际上是垂直测量的)。
然后我将设备旋转回横向模式,我的单元格从表格框架中溢出。
仅当表视图应用了旋转变换时才会出现此问题。如果我删除它,细胞就会完美更新。另外,我已经测试过,单个单元格旋转不会影响这个问题 - 只有整个表格视图转换是一个问题。
那么,以前有人遇到过这个问题吗...或者知道我如何控制单元格的宽度。此时我什至对流畅的动画不感兴趣。我只需要一些有用的东西。
谢谢,
编辑:
今天经过进一步调查,我发现旋转后,单元格将调整大小,以便它们使用表格的高度作为单元格的宽度和高度。
这意味着在旋转之后,我将始终拥有等于表格高度的方形单元格(我已经通过手动设置表格的高度对此进行了测试,并且它检查出来)。
更大的问题是,即使我在旋转后手动调整单元格的大小,新创建的单元格仍然会出现问题。不知何故,表格搞乱了他用于单元格宽度的值。 :(
In one of the screens of my application, I've implemented a horizontal scrolling tableview.
The method of choice was to apply a 90 degree rotation to the tableview, and then rotating each cell -90 degrees.
It all works well except for a problem with autorotation. I've spent the better half of this day on this but with no luck so far.
The tableview frame changes according to the table's autoresizingMasks and is OK. The problem is with the tableview cells which do not autoresize well.
I've managed to nicely resize the height of the cells (with a smooth animation) using this small piece of code the view controller.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[volumesPicker beginUpdates];
[volumesPicker endUpdates];
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:currentFocusedIndex inSection:0];
[volumesPicker scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
The problem is with the tableview cell width. For example:
I start the application with the device in landscape mode. The tableview is rendered nicely.
I rotate the device in portrait mode, and my cells suddenly have smaller widths than the table (remember, that the tableview is rotated so the width of the cell is actually measured vertically).
Then I rotate the device back in landscape mode, and my cells spill out from the table frame.
This problem happens only when the tableview has the rotation transform applied. If I remove it, the cells update perfectly. Also, I've tested and the individual cells rotation do not affect this problem - only the entire tableview transform is a problem.
So, has anybody encountered this problem before... or have any knowledge how I might control the width of a cell. At this point I'm not even interested in a smooth animation. I just need something that works.
Thank you,
EDIT:
Upon further investigation today, I have discovered that after the rotation, the cells will resize so that they use the height of the table as both width and height of the cell.
This means that after the rotation, I will always have square cells equal to the height of the table (I've tested this by manually setting the height of the table, and it checks out).
The bigger problem is that even if I manually resize my cells after the rotation, the newly created cells will still have the problem. Somehow the table fucks up the value he uses for the cell width. :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论