旋转时自动调整UITableView头大小(主要在iPad上) [英] Auto-Resize UITableView Headers on Rotate (Mostly on iPad)

查看:154
本文介绍了旋转时自动调整UITableView头大小(主要在iPad上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这将会是围绕着AutoResizingMasks的一个简单的答案,但我似乎无法围绕这个主题进行讨论。



我已经有一款iPad应用程序可以并排显示2个UITableView。当我从纵向旋转到横向时,UITableView中的单元格会在旋转发生时实时完美调整大小。我使用的是UITableViewCellStyleSubtitle UITableViewCells(现在不是子类),并且我已经在IB中设置了UITableView以锚定顶部,左侧和底部边缘(用于左侧的UITableView)并且具有灵活的宽度。



我为自己的UIView对象提供了

   - (UIView *)tableView :(UITableView *)tableView 
viewForHeaderInSection:(NSInteger)section

这是我的到目前为止(称为另一个类的类方法):

  +(UIView *)headerForTableView:(UITableView *)tv 
{
//视图返回
UIView * headerView = [[UIView alloc]
initWithFrame:CGRectMake(0,0,[tv frame] .size.width,someHeight )];

[headerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin];

//其他布局逻辑......似乎不是罪魁祸首

//返回HeaderView
return headerView;





$ b因此,无论哪种方向,一切都会像我想要的那样加载。轮换后,如果我手动调用reloadData或等到我的应用程序触发它,或者滚动UITableView,headerViews将调整大小并正确显示它们自己。我无法弄清楚如何正确获取AutoResizeMask属性,以便标题将像单元格一样调整大小。 解决方案

不是很好的解决方法。但作品:

   - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation持续时间:(NSTimeInterval)持续时间
{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
[mTableView reloadData];
}


I feel like this is going to be a simple answer revolving around AutoResizingMasks, but I can't seem to wrap my head around this topic.

I've got an iPad app that shows 2 UITableViews side-by-side. When I rotate from Portrait to Landscape and back, the cells in the UITableView resize perfectly, on-the-fly, while the rotation is occurring. I'm using UITableViewCellStyleSubtitle UITableViewCells (not subclassed for now), and I've set the UITableView up in IB to anchor to the top, left and bottom edges (for the left UITableView) and to have a flexible width.

I'm supplying my own UIView object for

- (UIView *)tableView:(UITableView *)tableView 
     viewForHeaderInSection:(NSInteger)section

Here's what I've got so far (called as a class method from another class):

+ (UIView *)headerForTableView:(UITableView *)tv
{
    // The view to return 
    UIView *headerView = [[UIView alloc] 
        initWithFrame:CGRectMake(0, 0, [tv frame].size.width, someHeight)];

    [headerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 
                                    UIViewAutoresizingFlexibleLeftMargin | 
                                    UIViewAutoresizingFlexibleRightMargin];

    // Other layout logic... doesn't seem to be the culprit

    // Return the HeaderView
    return headerView;
}

So, in either orientation, everything loads up just like I want. After rotation, if I manually call reloadData or wait until my app triggers it, or scroll the UITableView, the headerViews will resize and show themselves properly. What I can't figure out is how to get the AutoResizeMask property set properly so that the header will resize just like the cells.

解决方案

Not a very good fix. But works :

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
    [mTableView reloadData];
}

这篇关于旋转时自动调整UITableView头大小(主要在iPad上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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