0

当 iAd 显示时,我正在尝试调整表格视图的高度。

我正在使用以下代码。

CGRect bounds = [tableView bounds];
[tableView setBounds:CGRectMake(bounds.origin.x, 
                            bounds.origin.y, 
                            bounds.size.width, 
                            bounds.size.height - 100)];

我也尝试过框架而不是边界。

我知道 100 比我的广告的高度大,但看起来它从顶部和底部取下 50 并将表格垂直对齐在中心。而不是从底部减去 100。我的广告显示在底部。

我想知道是否可以自动调整大小,我从界面生成器中取出了底部的红色标记,但这并没有解决问题。

有什么建议么?

4

3 回答 3

0

试试这个:

CGRect bounds = [tableView bounds];
[tableView setBounds:CGRectMake(bounds.origin.x, 
                            bounds.origin.y - iAdHeight/2, 
                            bounds.size.width, 
                            bounds.size.height - iAdHeight)]; // Replace iAdHeight with height of iAd

您的代码不起作用,因为表格视图的原点位于中间,因此您必须在仅在底部垂直收缩时调整 y 值。

于 2012-04-17T21:52:44.823 回答
0

这将更改 tableView 的框架,使其底部小 100px。(您可以通过这种方式更改上、左、下、右,并使用负值再次增加大小)。

tableView.frame = UIEdgeInsetsInsetRect(tableView.frame, UIEdgeInsetsMake(0, 0, 100, 0));
于 2012-04-17T21:53:41.860 回答
0

不要混淆boundsframe。它们相似,但非常不同,如果您在更改bounds. 我通常只设置框架的边界,以获得初始大小。对于其他一切,我通常只是设置框架:

CGRect tableFrame = tableView.frame;
CGFloat iAdHeight = 50.f;
[tableView setFrame:CGRectMake(tableFrame.origin.x,
                               tableFrame.origin.y,
                               tableFrame.size.width,
                               tableFrame.size.height - iAdHeight)];

除非您做了一些奇怪的事情,例如更改表格视图上的锚点,否则这应该有效。

有关 和 之间的差异以及其他一些很棒的东西的良好参考boundsframeUIKit观看 WWDC 2011 视频 Session 121 - “Understanding UIKit Rendering”。

于 2012-04-17T22:54:40.500 回答