user1629827
user1629827

Reputation: 27

Auto Rotate while switching between View Controllers

I have a problem in programming. I have two view controllers. The first runs only in landscape left / right, the other runs only in portrait. If I switching between the views the orientation do not change automaticly. Only when I turn the device the orientation is changing. After that the orientation is fixed. Is it possible to change the orientation automaticly when I switching between the controllers?

As Example when I press the BackButton in the Landscape View Controller and it switch to the Portrait View Controller that the orientation automaticly switch from Landscape to Portrait?

Sorry for my bad english, it is not my native language.

Thanks, Tim

Upvotes: 3

Views: 656

Answers (2)

Sudan Hari
Sudan Hari

Reputation: 51

if(UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
{
  self.view.frame = CGRectMake(0,0,1024,768);
}
 else
{
  self.view.frame = CGRectMake(0,0,768,1024);
}

----use this code where you want to change---

Upvotes: 0

Siba Prasad Hota
Siba Prasad Hota

Reputation: 4789

Try the following Code for Portrait in Second View.

- (void)viewWillAppear:(BOOL)animated {
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

}

Try the following Code for Landscape in First View.

 - (void)viewWillAppear:(BOOL)animated {
        [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscape];

    }

Upvotes: 1

Related Questions