2013-04-26 108 views
0

我使用需要被允許,以適應iPhone 5的屏幕,但是我似乎無法得到正確的佈局視圖幫助,我已經嘗試了這一點;與iPhone 5視圖佈局

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    { 
     if (IS_IPHONE5) { 
      NSLog(@"iPhone 5"); 

      [SelectionPhotoOptionView setFrame:CGRectMake(470, 0, 640, 568)]; 
      [SelectionButView setFrame:CGRectMake(0, 0, 640, 568)]; 
      [imageViewSelection setFrame:CGRectMake(0, 0, 640, 568)]; 
      [imageViewPhotoOption setFrame:CGRectMake(-470, 0, 640, 568)]; 
      ButtonYpos=612; 

     } else { 

      NSLog(@"iPhone 4 and Lower"); 

     [SelectionPhotoOptionView setFrame:CGRectMake(470, 0, 320, 480)]; 
     [SelectionButView setFrame:CGRectMake(0, 0, 320, 480)]; 
     [imageViewSelection setFrame:CGRectMake(0, 0, 320, 480)]; 
     [imageViewPhotoOption setFrame:CGRectMake(-470, 0, 320, 480)]; 
     ButtonYpos=412; 
    } 

頂部是錯誤的,iPhone 5是不是制定了正確的,我不知道是否有人能幫助我了一個更簡潔的代碼示例使用?

謝謝, 克里斯

回答

1

您可以檢查您設備的分辨率是iPhone 5使用

#define IS_IPHONE ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] | [[[UIDevice currentDevice] model] isEqualToString:@"iPhone Simulator"]) 
#define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f 
#define IS_IPHONE_5 (IS_IPHONE && IS_HEIGHT_GTE_568) 

那麼你可以用下面的代碼替換代碼中設置框架(4英寸)或更低分辨率(3.5英寸):

if (IS_IPHONE) 
{ 
      [SelectionPhotoOptionView setFrame:CGRectMake(470, 0, 320, IS_IPHONE_5?568:480)]; 
      [SelectionButView setFrame:CGRectMake(0, 0, 320, IS_IPHONE_5?568:480)]; 
      [imageViewSelection setFrame:CGRectMake(0, 0, 320, IS_IPHONE_5?568:480)]; 
      [imageViewPhotoOption setFrame:CGRectMake(-470, 0, 320, IS_IPHONE_5?568:480)]; 
      ButtonYpos=IS_IPHONE_5?612:412; 
} 

注:在iPhone5的情況下,你已經給寬度爲640和iPhone 4是320雖然寬度同爲這兩個設備。所以我在兩種情況下都改變了寬度320。

它會爲你工作。

0

做檢查屏幕高度以下內容:

 screenRect = [UIScreen mainScreen].bounds; 
     screenHeight = screenRect.size.height; 
     if(screenHeight == 568){ 
      NSLog(@"iPhone 5"); 
     } 
     else NSLog (@"iPhone 4s or below"); 

當設置根據屏幕尺寸確保您搞清楚在導航欄,如果你有一個幀(默認大約40px)和狀態欄,我相信它是10px。

另外寬度爲320像素仍然,操作系統將自動調整爲視網膜顯示。

0

只需要兩個.xib iphone4和iphne5。它很容易,無需設置框架只需推適當的視圖/ xib。 像......

//設備兼容性

#define g_IS_IPHONE    ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"]) 
    #define g_IS_IPOD    ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"]) 
    #define g_IS_IPAD    ([[[UIDevice currentDevice] model] isEqualToString:@"iPad"]) 
    #define g_IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f 
    #define g_IS_IPHONE_4_SCREEN [[UIScreen mainScreen] bounds].size.height >= 480.0f && [[UIScreen mainScreen] bounds].size.height < 568.0f 

當你推,然後檢查屏幕..

if (g_IS_IPHONE_4_SCREEN) { 
      styleDetailObj =[[StyleDetailViewController_iPhone alloc] initWithNibName:@"StyleDetailViewController_iPhone" bundle:nil]; 
    } 
     else if (g_IS_IPHONE_5_SCREEN){ 
      styleDetailObj =[[StyleDetailViewController_iPhone alloc] initWithNibName:@"StyleDetailViewController_iPhone5" bundle:nil]; 
    } 

    [self.navigationController pushViewController:styleDetailObj animated:NO];