我的应用程序有一个带有五个选项卡的UITabBarController。 我只需要为第五个标签旋转方向。 通过子类化,我能够将所有五个旋转到横向 UITabBarController
@implementation TabBarControllerRotate
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationPortrait);
}
if(tbc == nil){
//tbc = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil]; ////// new //////
...
tbc.viewControllers =
[NSArray arrayWithObjects:viewController1, viewController2, viewController3
,viewController4,viewController5, nil];
我现在需要关闭viewController1 - 4的旋转; 我尝试通过将以下代码添加到四个* .m文件来尝试执行此操作失败 这些viewControllers。
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
请告诉我如何获得R完成。 感谢阅读,Mark
答案 0 :(得分:0)
我认为还有其他更简单的方法可以做到这一点,但我终于找到了解决方案。 TabBarController中第五个viewController的标题,唯一一个 需要改变方向的是“MyNotes”
在SubListViewController.m内部创建了TabBarControllerRotate对象。
tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil]; tbc.viewControllers = [NSArray arrayWithObjects:viewController1 , viewController2, viewController3, viewController4, viewController5, nil tbc.delegate = self;
TabBarController子类UITabBarController并包含BOOL属性 名字bMyNotes。
SubListViewController是一个UITabBarControllerDelegate
每次在TabBarController中更改视图时,都会发送一条消息,即 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
因此SubListViewController.m包含以下代码:
#pragma mark UITabBarControllerDelegate methods - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ BOOL b = (viewController.title == @"MyNotes"); [tbc setBMyNotesTab:b]; //NSLog(@"MyNotesTab == %d", [tbc bMyNotesTab]); }
然后TabBarControllerRotate.m包含:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { //NSLog(@"bMyNotesTab is: %d",self.bMyNotesTab); return ( (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationPortrait ) && self.bMyNotesTab );
}