本文介绍了什么是检测ios应用程序是否在iPhone,iPhone Retina显示器或iPad中运行的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检测ios app是否在iPhone,iPhone Retina显示器或iPad上运行的代码是什么?



背景:




  • 我的iPhone应用程序我已经在XCode目标/摘要页面中定义了以下特定图像:iPhone启动图像,iPhone视网膜显示启动图像,iPad肖像& iPad风景。


  • 在主视图中有一个UIImageView子视图我用于背景图像 - 目前我在XCode中指定了这个(不是以编程方式)选择我用于iPhone发布图像的图像。




所以我问怎么告诉我哪一个' m在内部运行,以便在viewDidLoad中我可以加载适当的分辨率背景图像。然后应用程序启动的背景图像与应用程序主屏幕启动后的背景应该是无缝过渡。

解决方案

您可以使用 [[UIDevice currentDevice] userInterfaceIdiom] 来确定无论您是在iPhone / iPod touch还是iPad上运行。



通常无需直接判断您是否在视网膜显示器上,因为 UIImage 在您使用 imageNamed 时自动处理并将@ 2x追加到您的高分辨率图像文件名中(参见。 / p>

如果你真的需要知道屏幕的分辨率,请使用 UIScreen 比例方法。


what is the code to detect whether ios app running in iPhone, iPhone Retina display, or iPad?

Background:

  • for my iPhone application I have defined in XCode target/summary page the specific images for: iPhone launch image, iPhone retina display launch image, iPad portrait & iPad landscape.

  • in the main view there is a UIImageView subview I use for the background image - currently I'm specifying this in XCode (not programmatically) by selecting the image I use for the iPhone launch image.

So I'm asking how to tell which one I'm running within so that in the viewDidLoad I can load the appropriate resolution background image. Then there should be a seamless transition between the background image for app startup, and the background of the app main screen once it's started.

解决方案

You can use [[UIDevice currentDevice] userInterfaceIdiom] to determine whether you're running on an iPhone/iPod touch or an iPad.

There's often no need to determine directly whether you're on a retina display because UIImage handles that automatically when you use imageNamed and append "@2x" to your high resolution image file names (see Supporting High-Resolution Screens in the Drawing and Printing Guide for iOS).

If you really need to know which resolution the screen has, use UIScreen's scale method.

这篇关于什么是检测ios应用程序是否在iPhone,iPhone Retina显示器或iPad中运行的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 10:59