0
votes

I'm wrestling with this problem. I need a portrait view and a landscape view for my App. Now when I create 2 buttons that show me a portrait view and a landscape view (forced by shouldAutorotateToInterfaceOrientation) they show up just fine. But when I call the views from within the result code of an imagepicker, the portraitview works just fine, but the landscape view get returned like this. http://bit.ly/bfbobc.

So just the make it clear: the nob is already turned 90 degrees, the imageviewcontrol is only shown half (the right part is off-screen)... But the iPhone isn't forced into landscape mode...

Can someone please explain me what's going on here or how I can achieve this! Any help is welcome!

This is how I call the views from withing the imagepickercontroller result code.

`- (void) imagePickerController:(UIImagePickerController *)vcImagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSLog(@"The picture was taken/chosen, now we need to decide which view to present");

[vcImagePicker dismissModalViewControllerAnimated:YES];

UIImage *chosenPicture = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

if (chosenPicture.size.width > chosenPicture.size.height) {
    NSLog(@"pic is in landscape");

    EditLandscapeScreen *vcEditLandscapeScreen = [[EditLandscapeScreen alloc] initWithNibName:@"EditLandscapeScreen" bundle:nil];
    vcEditLandscapeScreen.ChosenImage = chosenPicture;
    [self.view addSubview:vcEditLandscapeScreen.view]; 
    [vcEditLandscapeScreen release];
}
else {
    NSLog(@"pic is in portrait");

    EditPortraitScreen *vcEditPortraitScreen = [[EditPortraitScreen alloc] initWithNibName:@"EditPortraitScreen" bundle:nil];
    vcEditPortraitScreen.ChosenImage = chosenPicture;
    [self.view addSubview:vcEditPortraitScreen.view]; 
    [vcEditPortraitScreen release];
}

}`

1

1 Answers

1
votes

If you add a Subview to a View you have to make the Orientation changes for your Subview yourself. willRotateToInterfaceOrientation only will get called for the first viewcontroller so if you add Subviews to a viewcontroller this may be a acceptable way for you:

in your ViewController:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    for (int i = 0; i < [self.viewControllers count]; i++ ) {
        [[self.viewControllers objectAtIndex:i] didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    }
}

in you Subview ViewController:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    [self adjustViewsForOrientation:self.interfaceOrientation];
}

    - (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
        if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
            NSLog(@"Subview Landscape");
            //Do Your Landscape Changes here
        }
        else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
            NSLog(@"Subview Portrait");
            //Do Your Portrait Changes here
        }
    }

This may you get in the right direction.