在cocos2d建立的新工程運行結果螢幕都是橫向,控制碼
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{return UIInterfaceOrientationIsLandscape(interfaceOrientation); }
這段代碼控制的是螢幕視圖預設橫向顯示;
還有一個需要區別的是硬體裝置方向(灰黑色背景表示被選擇,所支援方向)
當你旋轉裝置方向時候,發現當螢幕豎著的時候,視圖裡面內容並未調整,標籤HelloWord並未橫著放
如果想讓運行時候預設豎屏,修改代碼傳回值(或者 return YES;也行)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{//return UIInterfaceOrientationIsLandscape(interfaceOrientation); return UIInterfaceOrientationIsPortrait(interfaceOrientation);}
裝置支援方向前兩個必選,後面兩個看需要,需要的話也可以選上;
UIInterfaceOrientationIsPortrait和UIInterfaceOrientationIsLandscape在UIApplication.h檔案中宏定義
#define UIInterfaceOrientationIsPortrait(orientation) ((orientation) == UIInterfaceOrientationPortrait || (orientation) == UIInterfaceOrientationPortraitUpsideDown)
#define UIInterfaceOrientationIsLandscape(orientation) ((orientation) == UIInterfaceOrientationLandscapeLeft || (orientation) == UIInterfaceOrientationLandscapeRight)