0

私のメイン ビュー コントローラーは で、タブ バーの項目はUITabBarController4です。UINavigationControllers各ナビゲーション バーは、スタックにプッシュされるいくつかの異なるビューです。

自動回転させたい単一のビューがありますがwillAnimateFirstHalfOfRotationToInterfaceOrientation、そのビュー コントローラー内で呼び出すことができません。

私は my UITabBarControllerandをサブクラス化し、次のようUINaviationControllersにオーバーライドを追加しようとしました:shouldAutorotateToInterfaceOrientation

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

その後も、ビューを回転させることはできません。一番上UIViewController(タブとナビゲーションを含む)は回転できる必要があるかもしれないと思いました。または、チェーンのすべてのビューでさえ。すべてのコントローラーをオーバーライドしようとしましshouldAutorotateToInterfaceOrientationたが、ビューを回転させることはできません。

誰かがこれを達成したか、何か提案がありますか?

前もって感謝します!

4

3 に答える 3

1

SubClassed を使用UITabBarController(または追加を使用) して、選択した navigationControllervisibleViewControllerに回転要求への応答を求めることができます。

@implementation RotatingTabBarController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        if([self.selectedViewController isKindOfClass:[UINavigationController class]]){
           return [[(UINavigationController*)self.selectedViewController visibleViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
        } else {
           return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
        }
}
@end
于 2009-11-17T01:07:22.740 に答える
1

houldAutorotateToInterfaceOrientation をオーバーライドしたように tabBarController をサブクラス化する以外に、次のことを行う必要があります。

回転するビューを追加するコントローラーの viewDidLoad メソッドで:

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

回転するビューを追加するコントローラーに、次のデリゲート メソッドを追加します。

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    //NSLog(@"didRotateFromInterfaceOrientation");


    if((fromInterfaceOrientation == UIInterfaceOrientationPortrait) ||
       (fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
    {    

        YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
    [mainDelegate.tabBarController.view addSubview: viewToBeRotated];

    [viewToBeRotated setHidden:NO];

    return;

}

if(fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
    [viewToBeRotated removeFromSuperview];
    [self.view setHidden:NO];
}

}

次のメソッドを追加することもできます。

- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
                                                duration:(NSTimeInterval)duration {

if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
    //self.view = self.portrait;
    YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
    [viewToBeRotated removeFromSuperview];
    mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
    mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
    mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);

}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
    YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
    [mainDelegate.tabBarController.view addSubview: viewToBeRotated];
    mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
    mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
    mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{


//self.view = self.portrait;
        YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
        [viewToBeRotated removeFromSuperview];
        mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
        mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
        mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
    }
    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
        [mainDelegate.tabBarController.view addSubview: viewToBeRotated];
        mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
        mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
        mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
    }
}

あなたも見てみたいかもしれません

iPhone を回転させ、新しい UIViewController をインスタンス化する

横向きモードの TabBarController と navigationController

于 2009-06-15T23:08:07.033 に答える
0

UITabBarController をサブクラス化し、このメソッドをオーバーライドするとうまくいきました:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

私の本当の問題は、更新されたコードをコンパイルしていない XCode だったと思います。Build clean を実行し、XCode とシミュレーターをタッチして再起動すると、最終的に変更が行われました。

于 2009-06-15T23:46:57.270 に答える