iOS force dock-bar/controls orientation

Previous topic - Next topic

DaCarSoft

Hi again...


To continue with my "XCode-Snippets", I will publish a code that solves the problem related to the GLBasic screen orientation and the iOS dock-bar when you double-click the home button in the iPad. And I says iPad because in the iPhone that bar is ever in portrait mode XDDDDDD but this code also can be used in an iPhone, someone knows why? Please, try to use this code before the code to call from GLBasic to the keyboard snippet that I published a couple of minutes ago...   XDDDD

Lets go:

In a ".mm" that you have to put into your XCode project:

Code (glbasic) Select

#if defined (TARGET_OS_IPHONE)

// UIINTERFACEORIENTATION

extern "C" void iOSSetOrientation(const char* cOrientation) {
    // Force the statusbar orientation avoiding confusions related to the parameters' case used from GLBasic
    if (strncasecmp(cOrientation,"landscapeleft",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
    }
    if (strncasecmp(cOrientation,"landscaperight",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
    }
    if (strncasecmp(cOrientation,"portrait",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
    }
    if (strncasecmp(cOrientation,"portraitupsidedown",strlen(cOrientation)) == 0) {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown];
    }
}

// FIN UIINTERFACEORIENTATION

#endif


If someone have code in a  .mm file generated before then does not include the lines started with the # symbol

After, from GLBasic, you can do something like this:

Code (glbasic) Select


IMPORT "C" void iOSSetOrientation(const char*)

iOSSetOrientation("Portrait")

PRINT "PRESS HOME TWICE!!!",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT

iOSSetOrientation("PortraitUpsideDown")

PRINT "PRESS HOME TWICE AGAIN!!!",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT

iOSSetOrientation("LandscapeLeft")

PRINT "AND... PRESS TWO TIMES AGAIN!",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT

iOSSetOrientation("LandscapeRight")

PRINT "¡¡¡ROLLING!!!!",100,100

SHOWSCREEN
HIBERNATE
MOUSEWAIT




With this you can rotate the GLBasic graphics, for example when you read the accelerometers values, and you can set the same orientation to iOS statusbar.

This code is ideal for use with the new rotation functions included in GLBasic 10.


Tell here your experience or questions...



Regards.
"Si quieres resultados distintos... no hagas siempre lo mismo" - Albert Einstein.