Wir haben einen UITabBarController programmgesteuert in unserer App hinzugefügt. Wir haben 3 UINavigationController in UITabViewController wie unten Code:Fix Ausrichtung von UIViewController
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:36.0/255.0 green:179.0/255.0 blue:125.0/255.0 alpha:1.0];
FirstViewController *VC1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *navControllerFirst = [[UINavigationController alloc]initWithRootViewController:VC1];
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"First" image:[UIImage imageNamed:@"First"] tag:0];
navControllerFirst.tabBarItem = item1;
SecondViewController *VC2 = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
UINavigationController * navControllerSecond = [[UINavigationController alloc]initWithRootViewController:VC2];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"Second" image:[UIImage imageNamed:@"Second"] tag:0];
navControllerSecond = item2;
ThirdViewController *callTransactionsNew=[[ThirdViewController alloc]initWithStyle:UITableViewStyleGrouped];
UINavigationController * navControllerThird = [[UINavigationController alloc]initWithRootViewController:callTransactionsNew];
UITabBarItem *item3 = [[UITabBarItem alloc] initWithTitle:@"Third" image:[UIImage imageNamed:@"Third"] tag:0];
navControllerThird = item3;
NSArray* controllers = [NSArray navControllerFirst, navControllerSecond, navControllerThird,nil];
self.tabBarController.viewControllers = controllers;
self.tabBarController.delegate = self;
self.tabBarController.view.frame = self.view.frame;
[self.tabBarController willMoveToParentViewController: self];
[self addChildViewController: self.tabBarController];
[self.view addSubview: self.tabBarController.view];
[self.tabBarController didMoveToParentViewController:self];
In didSelectViewController in TabBar- wir unten Code hinzugefügt. Dieser Code dreht FirstViewController in den Hochformat-Modus, wenn sich der Benutzer auf einer anderen Registerkarte im Querformat befindet und dann auf die erste Registerkarte klickt.
[UIViewController attemptRotationToDeviceOrientation];
if([theTabBarController.viewControllers indexOfObject:viewController] == 0) {
SEL sel = NSSelectorFromString(@"setOrientation:");
if([[UIDevice currentDevice] respondsToSelector:sel]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[[UIDevice currentDevice] performSelector:sel withObject:(__bridge id)((void*)UIInterfaceOrientationPortrait)];
#pragma clang diagnostic pop
}
}
Unsere Anforderung:
Wir wollen nur Porträt der Ausrichtung FirstViewController beheben. Es darf nicht rotieren. Rest UIViewControllers können sowohl im Querformat als auch im Hochformat gedreht werden. Kann mir bitte jemand helfen?
ja, wir sind. Es muss einen Weg geben. Ich habe andere Apps dabei gesehen. – varun