讲解如何禁止iOS屏幕自动旋转

在重力感应游戏中,经常会造成屏幕自动旋转的情况,这样会造成屏幕倒置,对操作造成不便,禁止重力感应的方法是:

在“项目/ios/RootViewController.mm”中,找到如下函数

// Override to allow orientations other than the default portrait orientation.

– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

// return UIInterfaceOrientationIsPortrait( interfaceOrientation );

#if defined(DISABLE_AUTO_ROTATE_ON_IPAD) && DISABLE_AUTO_ROTATE_ON_IPAD != 0

return interfaceOrientation == UIInterfaceOrientationPortrait;

#else

return YES;

#endif

} else {

return interfaceOrientation == UIInterfaceOrientationPortrait;

}

}