开发者

BUG when autorotating interfaces with horizontal scrolling UITableView

开发者 https://www.devze.com 2023-04-04 16:50 出处:网络
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 de

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 sm开发者_运维知识库ooth 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:

  1. I start the application with the device in landscape mode. The tableview is rendered nicely.

  2. 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).

  3. 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. :(

0

精彩评论

暂无评论...
验证码 换一张
取 消