2014-05-19 69 views
0

你好,我对iPhone开发(使用iOS 7)颇为陌生。基本上我希望我的应用程序响应屏幕旋转(即更改屏幕方向)我的项目同时使用UITabBarControllerUINavigationController。但是,当我旋转设备时,它不会在名为LoginView.mViewController中调用“shouldAutorotate”函数。UITabBarController和UINavigationController的子类化

因此,我已按照here中的回答,直到UITabBarControllerUINavigationController的子类。有人可以向我解释如何添加(即引用它)LoginView.m类或整个项目中的方向行为。

非常感谢您的帮助。

感谢

+0

有人吗?请帮助我.. – Yrol

+0

请详细阐述一下你试图达到的目标。 “shouldAutorotate”将被称为根视图控制器,在你的情况下,它是一个TabBarController或NavigationController,但我们需要更多关于期望结果的细节 – Argent

+0

@Argent基本上我想改变屏幕方向方面到屏幕旋转。我有一个名为LoginView.m的视图,它扩展了“UIViewController”。另外我在AppDelegate.m中看到UITabBarController和UINavigationController属性。如果你想让你的视图自动旋转,并且你正在使用基本的ios控件,那么请帮忙 – Yrol

回答

0

在你的子类的UITabBarController

- (BOOL)shouldAutorotate { 

    UINavigationController *navView = (UINavigationController *)[self selectedViewController]; 
    //Get the selected current tab viewcontroller. I guess you are having a Navigationcontroller  

    UIViewController *vc = [navView.viewControllers objectAtIndex:0]; 
    //Fetch root viewcontroller of your navigationcontroller 

    return [self checkOrientationForViewController:vc]; 

} 

-(BOOL) checkForViewsForViewController : (UIViewController *)vc{ 

    if([vc isKindOfClass:[FirstViewController class]]){ 

     FirstViewController *vc1 = (FirstViewController *)vc; 

     return [vc1 shouldAutorotate]; 
    } 
    if([vc isKindOfClass:[SecondViewController class]]){ 

     SecondViewController *vc2 = (SecondViewController *)vc; 

     return [vc2 shouldAutorotate]; 
    } 
    if([vc isKindOfClass:[ThirdViewController class]]){ 

     ThirdViewController *vc3 = (ThirdViewController *)vc; 

     return [vc3 shouldAutorotate]; 
    } 
    return YES; 
} 

在各自viewcontrollers实现shouldAutorotate方法

+0

感谢您的时间。我是否必须在AppDelegate文件中引用它以通知应用程序我正在使用这些自定义类? – Yrol

+0

是的,你必须导入它AppDelegate – iPrabu

+0

你能告诉我怎么做吗,这就是我困惑的地方。再次感谢 – Yrol

0

取而代之的子类,是值得知道的,也有委托方法,在UINavigationController的和的UITabBarController这使您可以在运行时处理旋转:

- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController 

Ref doc.

- (NSUInteger)tabBarControllerSupportedInterfaceOrientations:(UITabBarController *)tabBarController 

Ref doc

Evenf如果苹果已经移除了意见,不继承导航和TabBar控制器,使用代表团将随时间变化的最可靠的解决方案

+0

谢谢,我会给它一个去.. – Yrol

0

而不是使用代表团的你也可以使用

- (NSUInteger)supportedInterfaceOrientations 

的UINavigationController和UITabBarController询问他们的子视图控制器支持哪些接口方向。所以你可以在你的LoginView.m中实现“ - (NSUInteger)supportedInterfaceOrientations”并返回适当的接口方向。

您还需要编辑您的Info.plist并添加支持的接口方向。你可以通过打开项目视图来使用Xcode。也看看Apples documentation on supporting interface orientations

+0

谢谢,我会尽力..] – Yrol

相关问题