2014-02-21 125 views
0

我使用这两个设备,使我的application.my应用程序完美运行在iPad中,但是当我选择设备作为iPhone 4inch有一个错误发生interface.below是图片。 您可以在顶部和底部看到黑色,它来自哪里?做一个应用程序,这是兼容的iphone和ipad

enter image description here

这里是我的代码:

在应用委托

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { 
    if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) 
    { 
     NSLog(@"Ipad "); 
     [application setStatusBarStyle:UIStatusBarStyleLightContent]; 

     self.window.clipsToBounds =YES; 

     self.window.frame = CGRectMake(0,-20,self.window.frame.size.width,self.window.frame.size.height+20); 
    } 
    if 
    (IS_IPHONE_5) 
    { 

     NSLog(@"Iphone %f ",[[UIScreen mainScreen] bounds].size.height); 
     if ([[UIScreen mainScreen] bounds].size.height == 568) { 

      [application setStatusBarStyle:UIStatusBarStyleLightContent]; 

      self.window.clipsToBounds =YES; 

      self.window.frame = CGRectMake(0,-20,self.window.frame.size.width,self.window.frame.size.height+20); 
     } 
    } 

} 

enter image description here

+0

我想,你在iPhone 5设备上运行?对? – Mani

+0

@iMani yes right ..... – user3218052

回答

0

添加默认的视网膜图像为iPhone 5的640 * 1136

2

如果你想支持应用程序为iPhone 5屏幕。你应该添加图像,使iPhone 5的屏幕尺寸的应用程序。这应该从xcode执行4.5+

将图像添加到您的项目Xcode screenshot。 要使您的应用程序能够与iPhone 5一起使用,您需要添加视频版本的启动器映像。它应该被命名为[email protected]

将中心内容的自动调整掩码设置为在两个方向上展开。

view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

否则,您可以通过以下代码更改视图大小,这将使您的屏幕与iPhone 5屏幕兼容。

CGRect screenBounds = [[UIScreen mainScreen] bounds]; 
if (screenBounds.size.height == 568) { 
    // code for 4-inch screen 
} else { 
    // code for 3.5-inch screen 
} 
+0

我正在使用xcode5。 – user3218052

+0

我没有得到你请详细解释。 – user3218052

+0

导航栏仍然显示,但以轻微的方式显示屏幕截图 – user3218052

1

如果你想用两个iPad和iPhone(标准,3.5英寸,4英寸)兼容,试试这个

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ 
    if ([UIScreen mainScreen].scale == 2.0f) { 
     CGSize result = [[UIScreen mainScreen] bounds].size; 
     CGFloat scale = [UIScreen mainScreen].scale; 
     result = CGSizeMake(result.width * scale, result.height * scale); 

     if(result.height == 960){ 
      NSLog(@"iPhone 4, 4s Retina Resolution"); 
     } 
     if(result.height == 1136){ 
      NSLog(@"iPhone 5 Resolution"); 
     } 
     else { 
      NSLog(@"iPhone Standard Resolution"); 
     } 
    } 
    else { 
    //iPad 
     if ([UIScreen mainScreen].scale == 2.0f) { 
      NSLog(@"iPad Retina Resolution"); 
     } 
     else{ 
      NSLog(@"iPad Standard Resolution"); 
     } 
} 
相关问题