2011-03-12 82 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方法 - 它可以很容易地兩個視圖之間分割可用空間。