سؤال

I went through all the orientation threads I could find on here and implemented a few of them. each worked 90%. Here is some background on the app I am making. It has 5 tabBarItems each obviously loads a different view. Some of these view I want to do landscape and portrait however one view I only want to be portrait. I have this functioning some what. The HomeView needs to be portrait. It loads Portrait just fine and stays that way no mater how you rotate the phone However if you switch to another view which does support landscape, rotate the phone to landscape and then touch the HomeView tabBarItem it will load landscape even though it is set to only load portrait. Here is the current semi-working code in HomeView controller:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self orientationPortrait];

    NSLog(@"[INFO] %@ loaded",self);
 }   


-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:true];
    [self orientationPortrait];
   }

-(void)viewWillAppear:(BOOL)animated
{
    [self orientationPortrait];

}
-(void)viewWillDisappear:(BOOL)animated
{
    //NSLog(@"viewWillDisappear -- Start");
    [self orientationPortrait];
}


  -(void) orientationPortrait {
        TechBookAppDelegate *appDelegate = (TechBookAppDelegate *) [[UIApplication sharedApplication] delegate];
        appDelegate.screenIsPortraitOnly = YES;
    }
    -(void) orientationBoth{
        TechBookAppDelegate *appDelegate = (TechBookAppDelegate *) [[UIApplication sharedApplication] delegate];
        appDelegate.screenIsPortraitOnly = FALSE;
    }

In AppDelegate

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

    if(self.screenIsPortraitOnly == NO){
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskPortrait | !UIInterfaceOrientationMaskAll;
    }
}

The other tabBarItems ViewControllers have the same only they call the orientationBoth Method where needed and they call orientationPortrait on viewWillDisappear because I was hoping that when the view moves back to the HomeView that it would help set it to portrait but it doesn't seem to be working.

Please advise thanks.

هل كانت مفيدة؟

المحلول

I have fixed this issue by re-organizing the layout of the HomeViewController upon orientation change.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top