0

I have the following category defined to allow orientation in a TabBarController

@implementation UITabBarController (MyApp) 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

@end

Now there are a couple of viewcontrollers where I don't want to allow landscape-mode. Because I used categories the methods in the viewcontrollers are ignored. Is there a way to solve this?

(I know you can subclass UITabBarController but this is discouraged by Apple themself).

4

1 回答 1

0

您可以像这样询问您类别中的当前视图控制器:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return [[self selectedViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

您可能想要实现更多逻辑,具体取决于您的需要。此外,在您的情况下,子类化比自定义类别更好,全局覆盖事物可能会在未来的某个时候中断。

于 2012-04-28T09:50:46.603 回答