我在iOS中使用的是cocos2d
。在iOS中檢測iPhone的不同分辨率
我在檢測iphone5 resolution(1136*640)
時遇到問題。
我使用代碼:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
當我們在iPhone模擬器(4英寸)上運行的應用程序,它分別提供了屏幕寬度和screnHeight-320,480
。
誰能告訴我這個解決方案嗎?
我在iOS中使用的是cocos2d
。在iOS中檢測iPhone的不同分辨率
我在檢測iphone5 resolution(1136*640)
時遇到問題。
我使用代碼:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
當我們在iPhone模擬器(4英寸)上運行的應用程序,它分別提供了屏幕寬度和screnHeight-320,480
。
誰能告訴我這個解決方案嗎?
iPhone 5的分辨率僅爲1136 * 640。如果你想檢查只要登錄下面的代碼
分辨率,它會給準確(1136 * 640)
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);
NSLog(@"Screen SIze %@",NSStringFromCGSize (screenSize));
#define IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.width >= 568 || [[UIScreen mainScreen] bounds].size.height >= 568)?YES:NO
#define IS_IPHONE4 ([[UIScreen mainScreen] bounds].size.width >= 480 || [[UIScreen mainScreen] bounds].size.height >= 480)?YES:NO
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if(IS_IPHONE4)
{
// iPhone 4
}
if(IS_IPHONE5)
{
// iPhone 5
}
}
爲什麼downvoted可以說這是什麼錯誤? – Yohan
你可以在你的代碼添加檢查iPhone 4英寸屏幕和3.5英寸的屏幕
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic
// set your frames for classic iPhone here
}
if(result.height == 568)
{
// iPhone 5, iPhone 5S, iPhone 5C
// set your frames for 4 inch iPhone here
}
在.m文件中寫入此代碼。
#define WIDESCREEN (fabs((double)[ [UIScreen mainScreen ]bounds ].size.height-(double)568) < DBL_EPSILON)
現在你可以知道屏幕尺寸是這樣的。
if(WIDESCREEN)
{
NSLog(@"iPhone5 is here");
}
else
{
NSLog(@"iPhone4 is here");
}
的
可能重複[如何在iOS屏幕寬度和高度?(http://stackoverflow.com/questions/5677716/how-to-get-the-screen-width-and-height -in-ios) –
你不應該使用這些技巧,你的應用程序應該適應任何不同的尺寸。我很確定cocos2d已經爲你做了。 – Andrea
你可能在你的資源包中缺少1136x640的應用程序啓動默認圖像,而iOS會將應用程序裝箱到iPhone 4格式。 – YvesLeBorg