Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching between 2 view controllers on same storyboard, on rotation using willAutorotateTo... not working,

im having a little problem here. I have two view controllers on same storyboard (MainStoryboard -> Calc view Controller in portrait mode and Calc view controller in landscape mode). When i have initially created a boolforshouldAutoRotate it did rotate however there was "and still is" a rendering issue, as some buttons etc were not in the place you would expect them to be, in other words they were all over the place in landscape mode. So now i have created 2 view controllers in Landscape mode and main Portrait mode. So now the key is to switch between those two controllers on rotation.

in CalculatorViewController.m i have
UPDATE
I have noticed that some methods were deleted from iOS 6 ( and thats the one i am using now ) after a some research i have found that in iOS 6 the "sort of correct way " would be this

@synthesize portraitView, landscapeView;

-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations:toInterfaceOrientation
{
    if(UIInterfaceOrientationMaskAllButUpsideDown)
    {
        if ( UIInterfaceOrientationPortrait )
        {
            self.view = portraitView;
        }
        else if ( UIInterfaceOrientationLandscapeLeft )
        {
            self.view = landscapeView;
        }

    }
    return YES;

}    

however although i think i am using correct methods in respect to iOS 6 i still cant get the correct view controller to be called upon rotation

and in CalculatorViewController.h

@interface CalculatorViewController : UIViewController {


    IBOutlet UIView *portraitView; // declaring view - portrait
    IBOutlet UIView *landscapeView; // declaring view - landscape
    //rest of irrelevant code below

}
@property (nonatomic, retain) UIView *portraitView;
@property (nonatomic, retain) UIView *landscapeView;

enter image description here Just ignore those 2 white controllers they are now irrelevant. Submitting picture to show those 2 view controllers

Thank you for your time

like image 958
Maciej Cygan Avatar asked Oct 22 '22 16:10

Maciej Cygan


1 Answers

I've done things like this a couple of times, and it's frequently easier to have your ViewController have a blank view. Then just add your Landscape view as the prime subview in landscape, and then remove it when you rotate to portrait and so forth. If you try to have separate VC's then your going to have a tangled mess of state saving code just to smoothly transition.

You can even fiddle with this design by having both be constantly subviews, and just showing/hiding them when appropriate. This is more memory intensive, but you can do some nice transition animations.

That way all of your connections and logic will be in a single VC and just the interface will change.

like image 61
SethHB Avatar answered Nov 04 '22 00:11

SethHB