[[Director sharedDirector] setDeviceOrientation (ccDeviceOrientation)orientation];
*在AppDelegate的didFinishLaunchingWithOptions中,设置delegate为self,并重写下面方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //do something you need [director setDelegate:self]; } //support device orientation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return UIInterfaceOrientationIsLandscape(interfaceOrientation); }
//判断ui是否会随设备而旋转,先于supportedInterfaceOrientations执行 -(BOOL)shouldAutorotate{ return NO; } //设置ui支持的设备方向,需要和info.plist的target设置一样, //在shouldAutorotate返回YES时候才回执行 - (NSUInteger)supportedInterfaceOrientations { // return UIInterfaceOrientationMaskLandscapeLeft; // return UIInterfaceOrientationMaskLandscapeRight; return UIInterfaceOrientationMaskAll; }因此我们需要做对应修改,
@protocol CCDirectorDelegate <NSObject> @optional /** Called by CCDirector when the porjection is updated, and "custom" projection is used */ -(void) updateProjection; #ifdef __CC_PLATFORM_IOS /** Returns a Boolean value indicating whether the CCDirector supports the specified orientation. Default value is YES (supports all possible orientations) */ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; /** for IOS 6+ 这里添加两个方法*/ -(BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations ;2、在CCDirectorIOS.m中覆盖上面两个方法:
-(BOOL)shouldAutorotate{ BOOL ret =YES; if( [delegate_ respondsToSelector:_cmd] ) ret = (BOOL) [delegate_ shouldAutorotate]; return ret; } -(NSUInteger)supportedInterfaceOrientations{ int ret =UIInterfaceOrientationMaskAll; if( [delegate_ respondsToSelector:_cmd] ) ret = (int) [delegate_ supportedInterfaceOrientations]; return ret; }
//support ios 6+ -(BOOL)shouldAutorotate{ NSLog(@"AppDelegate--------shouldAutorotate"); return NO; } - (NSUInteger)supportedInterfaceOrientations { NSLog(@"AppDelegate--------supportedInterfaceOrientations"); return UIInterfaceOrientationMaskLandscapeLeft; }
[window_ setRootViewController:navController_];