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 に答える