iOS Rotate View Only One View Controller's View
Asked Answered
N

2

4

I have two view controllers in a single project. However, I want one of the view controller's to autorotate, and the other to not.

If I set the master project setting as seen below: enter image description here

Then, all view controllers autorotate, regardless of the following code in the view controller I do NOT want to autorotate:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        return YES;
    }
    return NO;
}

However, if I set the master project settings as seen below, the view controller that I do not want to autorotate does not, but that also means neither can the one that I DO want to.

enter image description here

How must I integrate the master project (plist file) settings with those of the view controllers so that one view controller will auto-rotate while the other will not?

Nicolas answered 18/8, 2012 at 18:28 Comment(2)
Check out this answerScrotum
How about your two ViewController relationship? for example. Push Relationship or Modal Relationshp.Moo
G
3
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

was depreciated in iOS 6 so if that's what your project is running, that's why it's not working. What you need to do is implement:

- (NSUInteger)supportedInterfaceOrientations
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

The first one will tell the controller what orientation(s) it is allowed to use, and the second will tell it which one to use first. Note that the first method is only called if the method shouldAutorotate: returns YES.

These are the constants you can use for supportedInterfaceOrientations:

UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown

Note that these only work on iOS 6.0.

Gavriella answered 5/12, 2012 at 19:4 Comment(0)
C
0

Assume I am using tabbarController & iOS<6.0 try to use the following code solve your issue:

//In First View Controller

//BOOL activeStatus;

-(void)viewWillAppear:(BOOL)animated
{
 activeStatus=YES;
}


-(void)viewWillDisappear:(BOOL)animated
{
 activeStatus=NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) && activeStatus==YES)
{
    return YES;
}

return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

//In Second View Controller

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

 return YES;
}
Cocke answered 14/3, 2013 at 7:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.