關于适配ios8、iPhone6、iphone plus以及資源優化相關問題
Coco2d版本:3.1.0.
Xcode:6.0.1
一、ios7及之前版本,universal程式準備3套資源:普清(320×480)、高清(1136×768)、ipadhd(2048×1536)。其中,iPhone 4、iphone5、ipad普清(1024×768)使用同一套資源。即背景圖使用1136×768,資源圖完全相同,針對ipad,使用如下代碼:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { //隻針對ipad使用該資源
[[CCFileUtils sharedFileUtils]setiPadSuffix:@"-hd"];//ipad使用-hd資源
}
二、針對ios8的适配
主要是Icon和launch image的操作。
在xcode工程中,command + N,——> iOS——》resource——》Asset Catalog。建立這樣一個檔案。
然後,在這個建立的xcassets檔案中,在其左側欄右鍵,點選new app icon會産生一個APPIcon檔案夾;new launch image,會建立1個LaunchImage檔案夾。
這2個檔案夾内就是你所需要提供的icon和launch image了。把你做好的icon和launch image放進這2個檔案夾,滑鼠拖曳到相應的欄位即可。
具體參數見:http://www.cocoachina.com/bbs/read.php?tid=229352&page=1
三、iphone6、iPhone6 plus的資源使用
1、iPhone6的圖檔資源使用同iPhone5、iPhone4,坐标調整最好使用autolayout.
-hd高清資源的背景圖統一調整為:1334×768,iPhone4、5、6以及非Retina的ipad都用這種尺寸的背景圖。其餘-hd的assets圖檔資源不變,繼續沿用即可。
2、iPhone6 plus圖檔資源使用ipadhd的資源。
具體操作:(1)在CCCConfiguration.m中,找到如下方法:-(NSInteger) runningDevice。
在此方法中找到這一行:ret = isiPhone5 ? CCDeviceiPhone5 : CCDeviceiPhone;
在這一行之下,if條件之外另起一行,寫入:
if ([UIScreen mainScreen].scale == 3.0f) { //iPhone6 plus的特征
ret = CCDeviceiPhoneRetinaDisplay;
}//end if
這幾行代碼可以讓iPhone6 plus使用“-hd”高清資源。
(2)在appdelegate.m中,applicationdidfinishlaunching中,加入:
if (DEVICE_IS_IPHONE6Plus) {
if((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) && ([CCDirector sharedDirector].contentScaleFactor == 3))
{
[CCDirector sharedDirector].contentScaleFactor = ([CCDirector sharedDirector].viewSizeInPixels.width/1024);
}
[[CCFileUtils sharedFileUtils]setiPhoneRetinaDisplaySuffix:@"-ipadhd"];//iphone6 plus使用-ipadhd資源
}
(3)自行調節坐标,以适應iPhone6 plus就可以了。
四、圖示icon上又出現了玻璃高光
在工程中選擇包含icon和launch image的images.xcassets檔案夾,選擇Appicon,打開右側邊欄,勾選“iOS icon is pre-rendered”即可,如下:
關于适配ios8、iPhone6、iphone plus以及資源優化相關問題
五、更新版本在iTunesconnect中上傳截圖,規格尺寸都對,就是上傳失敗,出現如下提示:
One or more screenshots are in the wrong size. For more information, see the Developer Guide.
原因:上傳的是ios模拟器自動生成的截圖,截圖命名中有漢字。把截圖用簡短的英文重命名即可。
六、上傳更新版本的app
出現如下問題:
關于适配ios8、iPhone6、iphone plus以及資源優化相關問題
原因:
工程中asset catalog裡面,APPIcon中有個carplay圖示是120×120的,這個圖示不應該加上,将其删除,再次上傳就ok了。
下面那個黃色警告可以無視。