user1940321
user1940321

Reputation:

iOS Orientation changing, but page is still vertical

So I've used the following code to load up a UIView when the device orientaiton changes, but when the page loads, the content on the page is not layed out the correct way. Any thoughts on how to change this?

Rotated without checking left and right in the project settings. Rotated without checking left and right in the project settings.

Rotated with checking left and right in the project settings. Rotated with checking left and right in the project settings. - I'm actually leaning toward this because at least the status bar is in the right area, but the downfall is that the width of the page isn't changing and allowing me to build horizontally...

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];


- (void)deviceOrientationDidChange{
        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        if (orientation == UIDeviceOrientationPortrait){
            NSLog(@"I'm portrait!");

        }
        else if (orientation == UIDeviceOrientationLandscapeLeft) {
            NSLog(@"I'm landscape LEFT!!");

        }
        else if (orientation == UIDeviceOrientationLandscapeRight) {
            NSLog(@"I'm landscape Right!!");

        }
        else {

        }
}

Upvotes: 0

Views: 93

Answers (3)

user1940321
user1940321

Reputation:

Was able to fix the issue using the code below by making some changes to the page in the didGainWindow method.

- (void)changePagePostionSettings{
    self.w = 568;
    self.h = 320;
    customBackground.w = 568;
    customBackground.h = 320;  
}

Upvotes: 0

zbMax
zbMax

Reputation: 2818

Your code is responding correctly to the changes of the device orientation.

The problem might come of how you have created your view.
The easiest way is with storyboard or IB, and set constraints, so when rotating, your view fits its new bounds.

Upvotes: 1

Pull
Pull

Reputation: 2246

Have you selected all the orientation in the General settings ?

enter image description here

Upvotes: 1

Related Questions