2013-10-04 43 views
0

我想在XCode 5的屏幕底部放置一個子視圖,但它在運行應用程序時會在底部留下20px的空間。在xCode Storyboard中使用視圖,但框架安裝不正確

我也改變了Deltas,不知道是什麼原因造成的。

我的代碼如下所示:

[bannerView setFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-bannerView.frame.size.width, 
           [UIScreen mainScreen].bounds.size.height-bannerView.frame.size.height - [UIApplication sharedApplication].statusBarFrame.size.height, 
           bannerView.frame.size.width, 
           bannerView.frame.size.height 
           )]; 

我的代碼看起來是這樣的:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 


    // Load Ad 

    self.bannerView.requestURL = @"http://adsivv.com/md.request.php"; 
    self.bannerView.delegate = self; 



- (void) viewWillLayoutSubViews { 

    NSLog(@"bannerView frame: %@", NSStringFromCGRect(bannerView.frame)); 

    [bannerView setFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-bannerView.frame.size.width, 
            [UIScreen mainScreen].bounds.size.height-bannerView.frame.size.height - [UIApplication sharedApplication].statusBarFrame.size.height, 
            bannerView.frame.size.width, 
            bannerView.frame.size.height 
            )]; 

} 

回答

0

*編輯 - 我看到了什麼問題。 CGRectMake()的前2個參數是x和y。 您可能想要將x保持爲0並將y向下移動。您正在使用這些參數的完整寬度和高度,可能會使視圖太靠右。看看它。

此代碼應該把你的屏幕上的橫幅廣告視圖:

- (void)viewWillLayoutSubViews { 
    [super viewWillLayoutSubViews]; 

    [self.bannerView setFrame:CGRectMake(0.0f, 
           0.0f, 
           self.bannerView.frame.size.width, 
           self.bannerView.frame.size.height 
           )]; 

    [self.view bringSubViewToFront:self.bannerView]; 
} 

右鍵該行之前:

NSLog(@"bannerView frame: %@", NSStringFromCGRect(bannerView.frame)); 

然後進行相應的調整。

+0

另外,你在-viewWillLayoutSubViews中調用你的代碼?這就是我所說的。 –

+0

不,我不把我的代碼放在那裏馬特。我還沒有創建這個類。你說'相應調整',但我會建議什麼?歡迎提出問題,但感謝您的幫助 – Omar

+0

好吧,我現在就開始工作了,謝謝!除了在iPhone 4上沒有顯示的情況。只有在iPhone 5.有什麼我應該改變編程? – Omar

相關問題