Native orientation and resolution – ShiVa Engine

Native orientation and resolution

capiright: “In this tutorial, you will learn how to support universal iDevice resolutions (iphone 1-5, ipad, ipod touch, …). This method works for Universal builds. Device rotations gain iOS support, including animations.”

Shiva setup

– Remove any device orientation call (setOption)

XCode setup

– Remove MainWindow_XXX.xib from the info.plist or from Targets->Summary->Main Interface. These fields should be empty.
– [Optional] Select the supported orientations in the same place. I selected both landscape views.
– [Optional] Add iphone5 splash screen

XCode code changes

[Optional] To support native Landscape mode, replace (in the same class under function initWithFrame)

if (self = [super initWithFrame: aRect])

With

CGRect rc = CGRectMake(0.0f, 0.0f, aRect.size.height, aRect.size.width);
    if (self = [super initWithFrame: rc])

Go to the main function in S3DEngine_IOS_Main.m, and replace

int retVal = UIApplicationMain(argc, argv, nil, nil);

With

int retVal = UIApplicationMain(argc, argv, nil, @"S3DEngine_AppDelegate" );

In S3DEngine_AppDelegate didFinishLaunching, add this code in the beginning:

//CAPI
    //I create the window programatically
    //Create the main window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ; //]rc];
   //Create the view controller
   viewController = [[S3DEngine_ViewController alloc] initWithNibName:nil bundle:nil];
   viewController.wantsFullScreenLayout = YES;
    //Create glView
    viewController.glView = [[S3DEngine_EAGLView alloc] initWithFrame:window.bounds];
    viewController.view = viewController.glView;
    self.window.rootViewController = viewController;

[Optional]: some external tools require you to initialize them from application:didFinishLaunching:WithOptions. To do that, just copy the entire function into that delegate and finish it by

return YES;

To support interface rotation to be managed by the operating system, make sure to implement the interface orientation delegates under S3DEngine_ViewController.
For iOS 5 and below:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return  UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

For iOS 6:

-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

Clean up your code: You can remove any IBOutlet prefix from you data members in the S3DEngine_ViewController and S3DEngine_AppDelegate




Need more answers?

  • slackBanner