iOS SDK是否提供了一种简单的方法来检查currentDevice是否具有高分辨率显示器(视网膜)?
我发现现在最好的方法是:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) {
// RETINA DISPLAY
}
Run Code Online (Sandbox Code Playgroud) 我在iOS 7和iOS 8中运行了以下代码:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL landscape = (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight);
NSLog(@"Currently landscape: %@, width: %.2f, height: %.2f",
(landscape ? @"Yes" : @"No"),
[[UIScreen mainScreen] bounds].size.width,
[[UIScreen mainScreen] bounds].size.height);
Run Code Online (Sandbox Code Playgroud)
以下是iOS 8的结果:
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 568.00, height: 320.00
Run Code Online (Sandbox Code Playgroud)
与iOS 7中的结果相比:
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 320.00, height: 568.00
Run Code Online (Sandbox Code Playgroud)
是否有任何文件指定此更改?或者它是iOS 8 API中的临时错误?
在Objective-C中,我们可以使用以下代码获取设备宽度和高度:
CGRect sizeRect = [UIScreen mainScreen].applicationFrame
float width = sizeRect.size.width
float height = sizeRect.size.height
Run Code Online (Sandbox Code Playgroud)
怎么能用Swift做到这一点?
因此,我使用最新版本的XCode创建了一个新项目,并尝试记录我的应用程序的屏幕大小(以确定UI的设备类型).我从iPhone 5运行了以下代码:
NSLog(@"%f", [[UIScreen mainScreen] bounds].size.height);
Run Code Online (Sandbox Code Playgroud)
这返回了480,这是旧iPhone系列的屏幕尺寸.我在模拟器中试过,发生了同样的事情.我必须在项目中启用一些属性来识别屏幕大小吗?
这仅适用于5个以上的设备; 如果我在iPad上运行游戏,它会识别1024屏幕尺寸.
我知道这个代码在过去有效.我使用完全相同的方法做了一段时间的游戏,它没有检测屏幕大小的问题,但这是在XCode 4.x中构建的.
我正在使用自定义视图控制器,我在App Delegate中创建了以下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if([Global getDevice] == 1)
{
//iPhone 5+
self.window.rootViewController = [[FivePlus alloc] initWithNibName:nil bundle:nil];
}
else if([Global getDevice] == 2)
{
//iPhone 4S-
self.window.rootViewController = [[FourSMinus alloc] initWithNibName:nil bundle:nil];
}
else
{
//iPad
self.window.rootViewController = [[iPad alloc] initWithNibName:nil bundle:nil];
}
[[self window] makeKeyAndVisible];
// Override point for customization after application launch.
return …Run Code Online (Sandbox Code Playgroud) 在此问题中发布的示例日志中,结果完全相同.有谁知道这两者之间是否存在逻辑差异?
即使是Apple的描述也令人困惑.以下是对的描述scale:
与屏幕关联的自然比例因子...此值反映了从默认逻辑坐标空间转换为此屏幕的设备坐标空间所需的比例因子...
以下是他们的描述nativeScale:
物理屏幕的本机比例因子
自然与本土有什么区别?
如何检测用户是否具有标准或缩放模式的iPhone 6 Plus?这可能吗?
在两种情况下,我都尝试过[UIScreen mainScreen].scale它3.0.
考虑到各种iOS设备和方向,获取当前屏幕分辨率的最简单方法是什么,包括高度和宽度?
如何在应用程序中编程改变亮度的能力?我知道它可能,因为我已经看到至少有三个应用程序可以做到这一点.这对我的应用程序非常有用.我知道它只能在iOS 5中使用UIScreen类,但我不知道如何编程.请帮我!
我正在使用此代码捕获屏幕截图并将其保存到相册中.
-(void)TakeScreenshotAndSaveToPhotoAlbum
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(window.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(window.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
Run Code Online (Sandbox Code Playgroud)
但问题是每当截图保存时,我都看不到iPhone的状态栏.相反,底部会出现一个空白区域.如下图所示:

我究竟做错了什么?
uiscreen ×10
ios ×9
iphone ×4
objective-c ×4
cocoa-touch ×2
ios8 ×2
brightness ×1
cgsize ×1
frame ×1
ios5 ×1
orientation ×1
swift ×1
uiwindow ×1