我想知道如何使用屏幕大小检测到iPhone 5。我的应用程序目前在iPhone 5上使用3.5英寸接口,所以当我使用代码时
CGSize结果= [UIScreen mainScreen界].size;
这给了我400,而不是屏幕大小的568英尺。那是因为我在iPhone 5上使用3.5英寸的界面,我知道我需要改变应用程序的布局,但是由于时间的限制,我想保持这种状态。
还是需要得到比例因子才能得到真正的像素?
CGFloat screenScale = [UIScreen mainScreen scale];
请帮帮我..。
发布于 2012-12-10 20:49:31
您可以很容易地检测iphone、iphone5和iPad,条件如下:-
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
}
else
{
//iphone 3.5 inch screen
}
}
else
{
//[ipad]
}
看看我在这个Detect device type上的答案
发布于 2012-12-10 15:34:59
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
// 4-inch
else
// 3.5-inch
发布于 2012-12-11 21:06:22
instead of find hight you have to use following code to find your device is iPhone 5 or below iphone 5.
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
-(void)ViewDidLoad
{
if(IS_IPHONE_5)
{
//code of iphone 5
}
else
{
//code of below iphone 5
}
}
https://stackoverflow.com/questions/13811087
复制相似问题