Search code examples
iphoneiosobjective-cjailbreak

Landscape Mode in WeeApp


I know there are a lot solved questions about UIDeviceOrientation in iOS, but no one worked for me. I want to make a label in the Widget centered in Landscape mode.

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
    ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight))
{
     d = 516; //my var to change the Position (The Value is just a test)
}

And this doesn't work for me for some reason...

Thanks in advance.


Solution

  • I just figured this out for my widget today. Define the method

    - (void)willAnimateRotationToInterfaceOrientation:(int)arg1
    

    for your AppController. Inside, check which orientation arg1 corresponds to with

    if (UIInterfaceOrientationIsLandscape(arg1)) {
        // you're in landscape mode
        float screenWidth = [UIScreen mainScreen].bounds.size.height;
    }
    else {
        // you're in portrait mode
        float screenWidth = [UIScreen mainScreen].bounds.size.width;
    }
    

    You can see my implementation of this in my file here. I figured it out by looking at the code for WeeFacebook.