1
votes

I am building an application with multiple UIViewControllers controlled by a RootViewController. Currently in the plist the application defaults to LandscapeRight.

Lets say I have the following files that can be loaded into the RootViewController:

  1. IntroView (Landscape Right ONLY)
  2. LandscapeView (Landscape Right ONLY)
  3. PortraitView (Portrait ONLY)

I also added into the RootViewController's shouldAutorotateToInterfaceOrientation the following:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([currentClass class] == PortraitView.class) {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);

} else {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

}

so all is well until I load in the PortraitView and in the viewWillAppear i add the following (similar to this thread

if (self.interfaceOrientation == UIInterfaceOrientationPortrait) { //UIInterfaceOrientationLandscapeRight) {      

    self.view.transform = CGAffineTransformIdentity;
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
    self.view.bounds = CGRectMake(0.0, 0.0, 320, 480);
    self.view.center = CGPointMake(240.0f, 160.0f);

}


[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

This yields a properly loaded in PortraitView but now my issue is that within my PortraitView I have 2 subviews that I would like to flip between, but because I rotated my view UIViewAnimationTransitionFlipFromLeft actually makes it flip top to bottom instead of left to right. I cannot for the life of me figure out how to tell PortraitView that its in Portrait.

When I check [[UIDevice currentDevice] orientation]; it tells me its in Landscape. When I attempt to use shouldAutorotateToInterfaceOrientation and set it to Portrait only it will then rotate my view so it is no longer correct.

Hopefully this makes sense! Been looking at this issue all day.

Thanks!

1
What is the superclass of RootViewController? Is it just a plain UIViewController?David Liu
Yes just a UIViewController. I'm not using any nav or tab bars.Anthony 'Ants' Nguyen

1 Answers

0
votes

I ran into this slightly differently; a UIViewController subclass in landscape mode that swapped top-to-bottom instead of left-to-right.

The fix that worked for me was to add all my views to a single “inner” view and then flip that instead of the UIViewController’s normal view.

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                           forView:[self innerView]
                             cache:YES];

Where [self innerView] is the sole child of [self view], and all the subviews are inside of it.