新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
当前回答
如果你的应用是为iPhone 4S或更早版本开发的,那么它将在iPhone 5上运行letterbox。
为了使你的应用程序适应新的更高的屏幕,你要做的第一件事是将启动图像更改为:Default-568h@2x.png。其大小应为1136x640 (HxW)。是的,在新的屏幕大小中设置默认图像是让你的应用占据整个新iPhone 5屏幕的关键。
(注意,命名约定只适用于默认映像。将另一个图像命名为“Image-568h@2x.png”不会导致它取代“Image@2x.png”被加载。如果你需要为不同的屏幕大小加载不同的图像,你必须通过编程来实现。)
如果你非常非常幸运,可能就是这样……但十有八九,你还得多走几步。
确保你的xib / view使用自动布局来调整自己的大小。 使用spring和struts来调整视图的大小。 如果这对你的应用不够好,设计你的xib/storyboard 的特定屏幕尺寸和以编程方式重新定位 其他。
在极端情况下(当以上都不满足时),设计两个xib并在视图控制器中加载适当的一个。
检测屏幕大小:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic
}
if(result.height == 568)
{
// iPhone 5
}
}
其他回答
如果你的应用是为iPhone 4S或更早版本开发的,那么它将在iPhone 5上运行letterbox。
为了使你的应用程序适应新的更高的屏幕,你要做的第一件事是将启动图像更改为:Default-568h@2x.png。其大小应为1136x640 (HxW)。是的,在新的屏幕大小中设置默认图像是让你的应用占据整个新iPhone 5屏幕的关键。
(注意,命名约定只适用于默认映像。将另一个图像命名为“Image-568h@2x.png”不会导致它取代“Image@2x.png”被加载。如果你需要为不同的屏幕大小加载不同的图像,你必须通过编程来实现。)
如果你非常非常幸运,可能就是这样……但十有八九,你还得多走几步。
确保你的xib / view使用自动布局来调整自己的大小。 使用spring和struts来调整视图的大小。 如果这对你的应用不够好,设计你的xib/storyboard 的特定屏幕尺寸和以编程方式重新定位 其他。
在极端情况下(当以上都不满足时),设计两个xib并在视图控制器中加载适当的一个。
检测屏幕大小:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic
}
if(result.height == 568)
{
// iPhone 5
}
}
在constants.h文件中,你可以添加以下定义语句:
#define IS_IPAD UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
#define IS_IPHONE UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone
#define IS_WIDESCREEN (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < DBL_EPSILON)
#define IS_IPHONE_5 (!IS_IPAD && IS_WIDESCREEN)
在这里你可以找到一个很好的教程(MonoTouch,但你也可以使用非MonoTouch项目的信息): http://redth.info/get-your-monotouch-apps-ready-for-iphone-5-ios-6-today/
为你的splash/default屏幕创建一个新图像(640 x 1136像素),名称为Default-568h@2x.png 在iOS模拟器中,转到硬件->设备菜单,并选择“iPhone(视网膜4英寸)” 创建其他图像,例如背景图像 检测iPhone 5加载你的新图像:
public static bool IsTall
{
get {
return UIDevice.currentDevice.userInterfaceIdiom
== UIUserInterfaceIdiomPhone
&& UIScreen.mainScreen.bounds.size.height
* UIScreen.mainScreen.scale >= 1136;
}
}
private static string tallMagic = "-568h@2x";
public static UIImage FromBundle16x9(string path)
{
//adopt the -568h@2x naming convention
if(IsTall())
{
var imagePath = Path.GetDirectoryName(path.ToString());
var imageFile = Path.GetFileNameWithoutExtension(path.ToString());
var imageExt = Path.GetExtension(path.ToString());
imageFile = imageFile + tallMagic + imageExt;
return UIImage.FromFile(Path.Combine(imagePath,imageFile));
}
else
{
return UIImage.FromBundle(path.ToString());
}
}
首先显示这张图片。在那个图像中,你显示了视网膜4支持的警告,所以点击这个警告,然后点击添加,这样你的视网膜4启动屏幕自动添加到你的项目中。
在你使用这段代码之后
if([[UIScreen mainScreen] bounds].size.height == 568)
{
// For iphone 5
}
else
{
// For iphone 4 or less
}
在iOS设备和iOS模拟器上测试时,有一个小问题。看起来模拟器(XCode 6.0.1)在[[UIScreen mainScreen] bounds]中给出了宽度和高度的切换值。大小,取决于设备方向。
因此,在确定正确的物理屏幕尺寸时,这可能是一个问题。此代码还有助于区分所有2014年。iPhone型号:
iPhone4s iPhone5(和iPhone5s) iPhone6(及iPhone6+)
它也可以很容易地改变,使区别,如iPhone6从iPhone6+。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
if (iOSDeviceScreenSize.width > 568 || // for iOS devices
iOSDeviceScreenSize.height > 568) // for iOS simulator
{ // iPhone 6 and iPhone 6+
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone6
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone6" bundle:nil];
NSLog(@"loaded iPhone6 Storyboard");
}
else if (iOSDeviceScreenSize.width == 568 || // for iOS devices
iOSDeviceScreenSize.height == 568) // for iOS simulator
{ // iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone5
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5" bundle:nil];
NSLog(@"loaded iPhone5 Storyboard");
}
else
{ // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
storyboard = [UIStoryboard story boardWithName:@"MainStoryboard_iPhone" bundle:nil];
NSLog(@"loaded iPhone4 Storyboard");
}
}
else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{ // The iOS device = iPad
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPadnew" bundle:nil];
NSLog(@"loaded iPad Storyboard");
}
// rest my code
}