旋转UITableView时调整单元格的大小 [英] Resize cells when rotating UITableView

查看:56
本文介绍了旋转UITableView时调整单元格的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只占视图底部三分之一的表格视图.

I have a tableview that occupies only the bottom third of my view.

我使用CGAffineTransform将其旋转90度并调整其大小:

I rotate it 90 degrees using CGAffineTransform and resize it:

[UIView beginAnimations:@"rotate" context:nil];
CGRect oldFrame = self.table.frame;
CGPoint oldCentre = self.table.center;
// Swap the width and height
self.table.frame = CGRectMake(0.0, 0.0, oldFrame.size.height, oldFrame.size.width);
self.table.transform = transform;
self.table.center = oldCentre;
[UIView commitAnimations];
[self.table reloadData];

因此,它从简短的胖人像视图变成了又高又瘦的风景视图.然后再回来.

So it goes from a short and fat portrait view to a tall and skinny landscape view. And back again.

我的单元格文本居中对齐.从高大而又瘦小的视图返回到短而胖的视图是行不通的.单元会在第一次调整大小,但保持调整大小!

My cell text has centre alignment. Going back from the tall and skinny view to the short and fat view doesn't work. The cells gets resized the first time, but stay resized!

如何使单元格正确调整大小?

How do you get the cells to resize properly?

推荐答案

我做了更多阅读,然后意识到了自己的错误.使用边界而不是框架.

I did some more reading and realised my mistake. Use bounds rather than frame.

CGRect oldBounds = self.table.bounds;

这似乎很好用.

这篇关于旋转UITableView时调整单元格的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆