以下是我的主要观点。
我在AppDeligate文件中有一个UITabBarController,如下所示。
UIViewController * viewController1 = [[[Grid1ViewController alloc] initWithNibName:@“Grid1ViewController”bundle:nil] autorelease]; UIViewController * viewController2 = [[[VideoListViewController alloc] initWithNibName:@“VideoListViewController”bundle:nil] autorelease]; UIViewController * viewController3 = [[[MusicViewController alloc] initWithNibName:@“MusicViewController”bundle:nil] autorelease]; UIViewController * viewController4 = [[[GalleryViewController alloc] initWithNibName:@“GalleryViewController”bundle:nil] autorelease];
UINavigationController * myNav1 = [[UINavigationController alloc] initWithRootViewController:viewController1]; UINavigationController * myNav2 = [[UINavigationController alloc] initWithRootViewController:viewController2]; UINavigationController * myNav3 = [[UINavigationController alloc] initWithRootViewController:viewController3]; UINavigationController * myNav4 = [[UINavigationController alloc] initWithRootViewController:viewController4];
UIImage * navBackgroundImg = [UIImage imageNamed:@“aa.png”];
[myNav1.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault]; [myNav2.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault]; [myNav3.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault]; [myNav4.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault];
self.tabBarController = [[[[UITabBarController alloc] init] autorelease]; self.tabBarController.viewControllers = [NSArray arrayWithObjects:myNav1,myNav2,myNav3,myNav4,nil];
4.我想锁定直接连接到tabBarController(ex-Grid1ViewController)的每个控制器的旋转。但我需要旋转应用程序中使用的某个控制器。请参考下图。 A,B,C,D和E是控制器。
我尝试在控制器和AppDeligate文件中实现以下方法。但没有奏效。当允许旋转时,整个应用程序开始旋转。
(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation {
NSLog(@“5轮”); return(toInterfaceOrientation == UIInterfaceOrientationPortrait); } //对于IOS 6
- (BOOL)shouldAutorotate { 的NSLog(@ “shouldAutorotate”); 返回YES; } (NSUInteger)supportedInterfaceOrientations { NSLog(@“6轮”); 返回UIInterfaceOrientationMaskPortrait; }
我怎样才能做到这一点?请帮忙。提前谢谢。