我在"viewDidLoad“中使用此代码来检查应用程序是在iPhone 5上运行还是在常规iPhone上运行。
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic
[_backgr setImage:[UIImage imageNamed:@"usefull_i4.png"]];
[scrollView setFrame:CGRectMake(16, 69, 291, 349)];
[_backgr setFrame:CGRectMake(0, 0, 320, 480)];
}
if(result.height == 568)
{
// iPhone 5
[_backgr setImage:[UIImage imageNamed:@"usefull_i5.png"]];
[scrollView setFrame:CGRectMake(15, 111, 295, 349)];
[_backgr setFrame:CGRectMake(0, 0, 320, 568)];
}
}它不起作用。:(只有在我改变的情况下!这里从iPhone 3.5到iPhone 4,这段代码可以工作。1
此外,我还将此代码用于另一个ViewController,效果很好。我不使用自动布局。
发布于 2013-03-22 13:01:40
尝试此宏:(在.pch文件中)
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )示例:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if(IS_IPHONE_5)
{
// code
}
}https://stackoverflow.com/questions/15563022
复制相似问题