- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
//----------------HERE WE SETUP FOR IPHONE 4/4s/iPod----------------------
if(iOSDeviceScreenSize.height == 480){
UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [iPhone35Storyboard instantiateInitialViewController];
// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = initialViewController;
// Set the window object to be the key window and show it
[self.window makeKeyAndVisible];
iphone=@"4";
NSLog(@"iPhone 4: %f", iOSDeviceScreenSize.height);
}
//----------------HERE WE SETUP FOR IPHONE 5----------------------
if(iOSDeviceScreenSize.height == 568){
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"iPhone5" bundle:nil];
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];
// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = initialViewController;
// Set the window object to be the key window and show it
[self.window makeKeyAndVisible];
NSLog(@"iPhone 5: %f", iOSDeviceScreenSize.height);
iphone=@"5";
}
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// NSLog(@"wqweqe");
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
}
return YES;
}
6 回答
这将为您提供整个屏幕的分辨率,因此iPhone最常用的是320x480 . 尽管iPhone4的屏幕尺寸要大得多,但iOS仍然可以提供320x480而不是640x960 . 这主要是因为较旧的应用程序崩溃 .
这将为您提供屏幕的比例 . 对于没有Retina显示器的所有设备,这将返回1.0f,而Retina显示设备将提供2.0f,而iPhone 6 Plus(Retina HD)将提供3.0f .
现在,如果您想获得iOS设备屏幕的像素宽度和高度,您只需要做一件简单的事情 .
通过乘以屏幕的比例,您可以获得实际的像素分辨率 .
有关iOS中像素和像素之间差异的详细信息,请阅读here .
EDIT: (Swift版本)
UIScreen类允许您以点和像素查找屏幕分辨率 .
屏幕分辨率以点或像素为单位 . 它绝不应与屏幕尺寸混淆 . 较小的屏幕尺寸可以具有更高的分辨率 .
UIScreen 's ' bounds.width'返回点的矩形大小
UIScreen 's ' nativeBounds.width'以像素为单位返回矩形大小 . 此值被检测为PPI(每英寸点数) . 显示设备上图像的清晰度和清晰度 .
您可以使用UIScreen类来检测所有这些值 .
Swift3
Console
Swift 2.x
ObjectiveC
在App Delegate中使用它:我正在使用故事板
对于iOS 8,我们可以使用这个
[UIScreen mainScreen].nativeBounds
,就像这样:请参阅UIScreen参考:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScreen_Class/Reference/UIScreen.html
使用此代码可以帮助您获取任何类型的设备屏幕分辨率