typedef enum {
eOrientationMode_INVALID,
eOrientationMode_Full,
eOrientationMode_Portrait,
eOrientationMode_Landscape,
eOrientationMode_COUNT
} eOrientationMode;
@interface RootViewController : UIViewController
<
UIImagePickerControllerDelegate
, UINavigationControllerDelegate
>
{
BOOL m_isOrientationLock;
eOrientationMode m_OrientationMode;
}
@property (nonatomic, readwrite) BOOL isOrientationLock;
@property (nonatomic, readwrite) eOrientationMode OrientationMode;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//
// There are 2 ways to support auto-rotation:
// - The OpenGL / cocos2d way
// - Faster, but doesn't rotate the UIKit objects
// - The ViewController way
// - A bit slower, but the UiKit objects are placed in the right place
//
#if GAME_AUTOROTATION==kGameAutorotationNone
//
// EAGLView won't be autorotated.
// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
//
return ( interfaceOrientation == UIInterfaceOrientationPortrait );
#elif GAME_AUTOROTATION==kGameAutorotationCCDirector
//
// EAGLView will be rotated by cocos2d
//
// Sample: Autorotate only in landscape mode
//
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {
[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight];
} else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft];
}
// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
return ( interfaceOrientation == UIInterfaceOrientationPortrait );
#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
//
// EAGLView will be rotated by the UIViewController
//
// Sample: Autorotate only in landscpe mode
//
// return YES for the supported orientations
if (m_isOrientationLock) {
return NO;
}
switch (m_OrientationMode) {
case eOrientationMode_INVALID:
return NO;
break;
case eOrientationMode_Full:
return YES;
break;
case eOrientationMode_Portrait:
return ( UIInterfaceOrientationIsPortrait(interfaceOrientation) );
break;
case eOrientationMode_Landscape:
return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );
break;
default:
return NO;
break;
}
#else
#error Unknown value in GAME_AUTOROTATION
#endif // GAME_AUTOROTATION
// Shold not happen
return NO;
}
コメントする