Anu*_*rag 209
从我今天的演示文稿中可以看出,所有应用程序将继续在垂直拉伸的屏幕中工作.它们将是letterboxed或基本上额外的88点高度将只是黑色.
如果您只打算支持iOS 6+,那么一定要考虑使用自动布局.它删除了所有固定的布局处理,而是使用约束来解决问题.没有什么是硬编码的,你的生活将变得更加简单.
但是,如果您必须支持较旧的iOS,那么它实际上取决于您的应用程序.大多数使用标准导航栏和/或标签栏的应用程序可以简单地扩展中间的内容以消耗额外的点数.设置中心内容的自动调整遮罩以在两个方向上展开.
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Run Code Online (Sandbox Code Playgroud)
它可以很好地开箱即用于桌面视图,但是,如果您的应用使用像素完美的布局来显示内容,那么您最好的选择是重新设想内容,以便它可以适应不同的高度.
如果这不可能,那么剩下的唯一选择就是拥有两个UI(iPhone 5和iPhone 5之前).
如果这听起来很难看,那么你可以使用默认的letterboxed模型,其中额外的点/像素只显示黑色.
编辑
要使您的应用能够与iPhone 5配合使用,您需要添加启动器图像的视网膜版本.应该命名Default-568h@2x.png.它必须是视网膜质量 - 这里没有向后兼容性:)
您也可以从Xcode中选择此图像.转到目标,然后在"摘要"部分下,查找"启动图像".图像的大小必须为640x1136像素.这是一个截图,在哪里找到它,如果这有帮助.

dan*_*emm 84
您需要添加640x1136像素的PNG图像(Default-568h@2x.png)作为项目的4英寸默认启动图像,并且它将使用额外的空间(在基于简单表格的应用程序上不费力,游戏将需要更多努力).
我已经创建了一个小的UIDevice类别来处理所有屏幕分辨率.你可以在这里得到它,但代码如下:
enum {
UIDeviceResolution_Unknown = 0,
UIDeviceResolution_iPhoneStandard = 1, // iPhone 1,3,3GS Standard Display (320x480px)
UIDeviceResolution_iPhoneRetina4 = 2, // iPhone 4,4S Retina Display 3.5" (640x960px)
UIDeviceResolution_iPhoneRetina5 = 3, // iPhone 5 Retina Display 4" (640x1136px)
UIDeviceResolution_iPadStandard = 4, // iPad 1,2,mini Standard Display (1024x768px)
UIDeviceResolution_iPadRetina = 5 // iPad 3 Retina Display (2048x1536px)
}; typedef NSUInteger UIDeviceResolution;
@interface UIDevice (Resolutions)
- (UIDeviceResolution)resolution;
NSString *NSStringFromResolution(UIDeviceResolution resolution);
@end
Run Code Online (Sandbox Code Playgroud)
#import "UIDevice+Resolutions.h"
@implementation UIDevice (Resolutions)
- (UIDeviceResolution)resolution
{
UIDeviceResolution resolution = UIDeviceResolution_Unknown;
UIScreen *mainScreen = [UIScreen mainScreen];
CGFloat scale = ([mainScreen respondsToSelector:@selector(scale)] ? mainScreen.scale : 1.0f);
CGFloat pixelHeight = (CGRectGetHeight(mainScreen.bounds) * scale);
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
if (scale == 2.0f) {
if (pixelHeight == 960.0f)
resolution = UIDeviceResolution_iPhoneRetina4;
else if (pixelHeight == 1136.0f)
resolution = UIDeviceResolution_iPhoneRetina5;
} else if (scale == 1.0f && pixelHeight == 480.0f)
resolution = UIDeviceResolution_iPhoneStandard;
} else {
if (scale == 2.0f && pixelHeight == 2048.0f) {
resolution = UIDeviceResolution_iPadRetina;
} else if (scale == 1.0f && pixelHeight == 1024.0f) {
resolution = UIDeviceResolution_iPadStandard;
}
}
return resolution;
}
@end
Run Code Online (Sandbox Code Playgroud)
这是您需要使用此代码的方式.
1)将上述UIDevice + Resolutions.h和UIDevice + Resolutions.m文件添加到您的项目中
2)将#import"UIDevice + Resolutions.h"行添加到ViewController.m中
3)添加此代码以检查您正在处理的设备版本
int valueDevice = [[UIDevice currentDevice] resolution];
NSLog(@"valueDevice: %d ...", valueDevice);
if (valueDevice == 0)
{
//unknow device - you got me!
}
else if (valueDevice == 1)
{
//standard iphone 3GS and lower
}
else if (valueDevice == 2)
{
//iphone 4 & 4S
}
else if (valueDevice == 3)
{
//iphone 5
}
else if (valueDevice == 4)
{
//ipad 2
}
else if (valueDevice == 5)
{
//ipad 3 - retina display
}
Run Code Online (Sandbox Code Playgroud)
Han*_*son 56
我刚刚完成更新并将其中一个应用程序的iOS 6.0版本发送到商店.此版本向后兼容iOS 5.0,因此我保留了该shouldAutorotateToInterfaceOrientation:方法并添加了下面列出的新方法.
我必须做以下事情:
iOS 6中的自动旋转正在发生变化.在iOS 6中,shouldAutorotateToInterfaceOrientation:不推荐使用UIViewController 的方法.取而代之的是,你应该使用supportedInterfaceOrientationsForWindow:和shouldAutorotate方法.因此,我添加了这些新方法(并保持旧的iOS 5兼容性):
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
viewWillLayoutSubviews方法并使用视图的边界矩形调整布局.willRotateToInterfaceOrientation:duration:,willAnimateRotationToInterfaceOrientation:duration:以及didRotateFromInterfaceOrientation:方法不再调用的任何视图控制器上,使一个全屏幕呈现在presentViewController:animated:completion:.Default-568h@2x.png并且大小为640×1136.它也允许为相同的肖像模式提供640×1096(状态栏已删除).如果您的应用仅允许iPhone上的横向显示,也可以在横向模式下提供相似的尺寸.armv6代码的支持已被删除.因此,我现在能够支持的所有设备(正在运行armv7)都可以升级到iOS 5.这只是记得在iOS 5和iOS 6中测试自动旋转因为旋转的变化.
use*_*691 26
没有.
if ([[UIScreen mainScreen] bounds].size.height > 960)
Run Code Online (Sandbox Code Playgroud)
在iPhone 5上是错误的
if ([[UIScreen mainScreen] bounds].size.height == 568)
Run Code Online (Sandbox Code Playgroud)
end*_*ndy 17
@interface UIDevice (Screen)
typedef enum
{
iPhone = 1 << 1,
iPhoneRetina = 1 << 2,
iPhone5 = 1 << 3,
iPad = 1 << 4,
iPadRetina = 1 << 5
} DeviceType;
+ (DeviceType)deviceType;
@end
Run Code Online (Sandbox Code Playgroud)
.M
#import "UIDevice+Screen.h"
@implementation UIDevice (Screen)
+ (DeviceType)deviceType
{
DeviceType thisDevice = 0;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
thisDevice |= iPhone;
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)])
{
thisDevice |= iPhoneRetina;
if ([[UIScreen mainScreen] bounds].size.height == 568)
thisDevice |= iPhone5;
}
}
else
{
thisDevice |= iPad;
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)])
thisDevice |= iPadRetina;
}
return thisDevice;
}
@end
Run Code Online (Sandbox Code Playgroud)
这样,如果您想要检测它是iPhone还是iPad(无论屏幕尺寸如何),您只需使用:
if ([UIDevice deviceType] & iPhone)
Run Code Online (Sandbox Code Playgroud)
要么
if ([UIDevice deviceType] & iPad)
Run Code Online (Sandbox Code Playgroud)
如果您只想检测iPhone 5,可以使用
if ([UIDevice deviceType] & iPhone5)
Run Code Online (Sandbox Code Playgroud)
与Malcoms的答案相反,你需要检查一下,看看它是不是iPhone,
if ([UIDevice currentResolution] == UIDevice_iPhoneHiRes ||
[UIDevice currentResolution] == UIDevice_iPhoneStandardRes ||
[UIDevice currentResolution] == UIDevice_iPhoneTallerHiRes)`
Run Code Online (Sandbox Code Playgroud)
这两种方式都没有相互优势,这只是个人偏好.
@Pascal对OP问题的评论是正确的.只需添加图像,它就会删除黑色边框,应用程序将使用全高.
您需要通过确定设备使用更大的显示器来对任何CGRect进行调整.即如果你需要一些与屏幕底部对齐的东西.
我确信有一个内置的方法,但我还没有看到任何东西,而且很多仍然在NDA下,所以我们在我们的应用程序中使用的方法非常简单的全局功能.将以下内容添加到.pch文件中,然后进行简单if( is4InchRetina() ) { ... }调用以调整CGRects等.
static BOOL is4InchRetina()
{
if (![UIApplication sharedApplication].statusBarHidden && (int)[[UIScreen mainScreen] applicationFrame].size.height == 548 || [UIApplication sharedApplication].statusBarHidden && (int)[[UIScreen mainScreen] applicationFrame].size.height == 568)
return YES;
return NO;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
161170 次 |
| 最近记录: |