2011-03-12 85 views
1

我有一个这样的视图层次:UIView的自动尺寸问题

 
UIView 
    - ADBannerView 
    - UIImageView 
    - UILabel 
    - UIButton 
    - UINavigationController 
    - UIView 

我加载从笔尖文件从另一个笔尖图像视图,标签和按钮和UINavigationController的。所有都有自动调整掩码设置。我以编程方式创建ADBannerView。

现在我的问题是,我想的图像,标签,按钮向下移动和导航控制器,当我插入ADBannerView萎缩。但是,这不会发生,而是将ADBannerView放置在图像和标签的顶部。

可有人向我解释,我在做什么错在这里?

+0

我不能说对iAds的集成到应用程序中对雷Wenderlich的教程足够的好东西。他直接解决这个问题:http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-app – 2011-03-12 23:48:01

+0

哦,并作为一个侧面说明...忘记将iAds集成到你的应用程序。您最好集成AdWhirl,它允许您同时使用iAd,AdMob和其他一些广告框架。 https://www.adwhirl.com/我甚至不担心别人,而是拥有的iAd和AdMob在同一地点的能力是巨大的。 iAd仅在8%的时间内投放广告,这意味着您错过了92%的收入。用AdMob填充其余部分! – 2011-03-13 00:25:20

回答

3

在其他让这些东西为“自动”降档时,你把ADBannerView,你需要将它们封闭在自己的视图,然后更改视图的大小和位置。假设ADBannerView的高度为50像素,则需要将该UIView向下移动50个像素,并将其高度降低50个像素。

假设self.enclosingView是您将用于包围图像,标签和按钮的新视图...并且假设您想使其成为动画(您可能会这样做,它通常看起来好多了):

// Start the AdBannerView off of the top of the screen 
CGRect adFrame = self.bannerView.frame; 
adFrame.origin.x = 0.0; 
adFrame.origin.y = 0.0 - adFrame.size.height; 
self.bannerView.frame = adFrame; 

[UIView beginAnimations:@"Show Ads" context:nil]; 

// Animate the shrinking of the enclosing view 
CGRect enclosingFrame = self.enclosingView.frame; 
enclosingFrame.size.height -= self.bannerView.frame.size.height; 
enclosingFrame.origin.y += self.bannerView.frame.size.height; 
self.enclosingView.frame = enclosingFrame; 

// Animate the motion of the bannerView into view 
adFrame.origin.y = 0.0; 
self.bannerView.frame = adFrame; 

[UIView commitAnimations]; 
+0

谢谢。我希望这可以自动完成,并考虑到这是最后的手段,但正如hoha指出的,自动调整仅适用于父/子调整大小。我知道它的工作没有问题,但动画效果不错。 :) – mirosval 2011-03-13 00:25:13

1

自动调整掩码定义父级帧更改上的大小更改,而不是同级插入/删除。您必须以编程方式调整相应视图的框架。 Kenny Wyland已经告诉你如何以较少的痛苦实现这个目标。看看CGRectDivide方法 - 它可以很容易地两个视图之间分割可用空间。