2012-02-28 71 views
0

我想顯示addview我的屏幕的底部,我的應用程序是通用的,所以我在viewDidLoad中使用此代碼爲什麼addview不適合在寬

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
     { 
      if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) 
      { 
       adView= [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 80.0f, 320.0f, 40)]; 

      } 
      else 
      { 
       NSLog(@"///////////////////////////// I'm here /////////////////////"); 
       adView= [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 80.0f, 1024 , 40)]; 


      } 
     } 
     else 
     { 
      if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) 
      { 
       adView= [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 40.0f, 320.0f, 40)]; 

      } 
      else 
      { 
       adView= [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 40.0f, 1024 , 40)]; 


      } 

     } 

     [adView setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin]; 
     //adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50; 




     [self.view addSubview: adView]; 
     [self.view bringSubviewToFront:adView]; 

的問題是,鑑於從未在iPhone上運行,並不能很好的工作填補了寬度在ipad

任何想法如何解決 enter image description here 問候

回答

1

它不會在所有在iPhone上工作,因爲所有的位置代碼,你個人有T這裏僅適用於iPad,因爲代碼在該區塊內。

至於填充的寬度,因爲你沒有說出現什麼。

+0

當然iPad的寬度應該是768或1024。 – ader 2012-02-28 17:06:55

+0

我更新了我的問題,並取決於Apurv我更新了照片 – AMH 2012-02-28 19:07:35

2

我更新了代碼。

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
     { 
      if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) 
      { 
       adView= [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 80.0f, 768.0f, 40)]; 

      } 
      else 
      { 
       NSLog(@"///////////////////////////// I'm here /////////////////////"); 
       adView= [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 80.0f, 1024 , 40)]; 


      } 
     } 
     else 
     { 
      if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) 
      { 
       adView= [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 40.0f, 320.0f, 40)]; 

      } 
      else 
      { 
       adView= [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 40.0f, 480 , 40)]; 


      } 

     } 
+0

我的代碼工作良好,但不是在ipad的風景中,因爲你可以在我的更新圖片中看到 – AMH 2012-02-28 19:07:00

+0

當你改變方向時,你將不得不相應地調整框架。以上代碼將根據初始方向創建視圖。 – Apurv 2012-02-29 04:08:36

+0

此視圖不會改變您的方向 – AMH 2012-02-29 08:23:46