简体   繁体   中英

iOS Orientation issue from landscape to portrait

I've lost enough sleep trying to figure this one out. I have a tabbed application that supports all orientations. Everything works completely fine when the app starts in portrait and switches to landscape. When the app starts in landscape however and then switches to portrait, I lose response ONLY on the bottom quarter of the screen! It's as if something in the background is not adjusting the "user interaction" area from landscape bounds to portrait bounds when the orientation changes.

I have two tabs at the moment. When I switch to the second tab, and then back to the first, the problem goes away! I'm able to interact with the bottom quarter of the screen again. I've gotten that similar problem before when I setup the tab view controller away in viewDidLoad as opposed to viewDidAppear. Everything is in viewDidAppear now.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
  [super viewDidLoad];
}

- (void)viewDidAppear:(BOOL)animated
{
NSArray* controllers = nil;

    TimeTableViewController * timeTableViewController = [[TimeTableViewController alloc] init];

    FRLayeredNavigationController *timeTableNavController = [[FRLayeredNavigationController alloc] initWithRootViewController:timeTableViewController configuration:^(FRLayeredNavigationItem *item)
    {
        item.hasChrome = YES;

    }];
    timeTableNavController.dropLayersWhenPulledRight = true;



    TestViewController* vc2 = [[TestViewController alloc] init];
    timeTableNavController.tabBarItem = [[UITabBarItem alloc]
                      initWithTitle:@"Student Lookup"
                      image:[UIImage imageNamed:@"search_gray.png"]
                      tag:0];


    timeTableNavController.tabBarItem = [[UITabBarItem alloc]
                                         initWithTitle:NSLocalizedString(@"Attendance", @"Attendance")
                                         image:[UIImage imageNamed:@"attendance_gray.png"]
                                         tag:0];
    timeTableNavController.view.backgroundColor = [UIColor lightGrayColor];

controllers = [NSArray arrayWithObjects:timeTableNavController,vc2, nil];
self.viewControllers = controllers;

}

- (BOOL)shouldAutorotateToInterfaceOrientation:  (UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

I don't think the FRLayeredNavigationController library is an issue. Is there any method I can call that readjusts the "area of response" when switching from landscape to portrait? That would be a life-saver. Someone please beat some sense into me!

In fact when you start your app in landscape mode, it should starts in portrait and then your viewcontroller need to rotate this.

In fact you have 3 approaches:

  1. First and i think the best: https://stackoverflow.com/a/10533561/2204866
  2. Or you can create separates views with separate xib's for each mode. Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?
  3. And the last use auto layout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM