3

iPad コードに問題があります。

UIViewController と UISplitViewController を保持する UITabBarController があります。問題は、UIViewController と UISplitViewController でさえ、向きの変更を正しく認識しないことです。

TabBarController とすべての UIViewControllers に shouldAutorotateToInterfaceOrientation を設定しましたが、TabBarController である Top moast ViewController の willRotateToInterfaceOrientation のみが起動することに気付きました。TabBarController から shouldAutorotateToInterfaceOrientation を削除すると、サブ UIViewControllers から willRotateToInterfaceOrientation が呼び出されます。最大の問題は私の UISplitViewController です。これは、新しい interfaceOrientation に回転しますが、Portrait Layout で動かなくなるためです。

向きの変更を含む ViewControllers と Splitviews を使用して TabBarController を正しく実装するにはどうすればよいですか?

4

2 に答える 2

0

ねえ、私は今自分で回避策を思いつきました。問題の要約 ウィンドウへの最初のアドデット ビューのみが方向の変更を認識します。

私は My TabBarController をサブクラス化し、Rotate to the Interface Orientation にしました

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self adjustViewsForOrientation:toInterfaceOrientation];    
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"Landscape");
        //Do Your Landscape Changes here


    }
    else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        NSLog(@"Portrait");
        //Do Your Portrait Changes here
    }
}

しかし、私のTabBarControllerの「viewControllers」はまだInterfaceOrientationsを認識しません。だから私は次のことを思いついた:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    for (int i = 0; i < [self.viewControllers count]; i++ ) {
        [[self.viewControllers objectAtIndex:i] didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    }
}

これにより、TabBarController のすべてのサブクラスから didRotateFromInterfaceOrientation メソッドが呼び出されます。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    [self adjustViewsForOrientation:self.interfaceOrientation];
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"Subview Landscape");
        //Do Your Landscape Changes here
    }
    else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        NSLog(@"Subview Portrait");
        //Do Your Portrait Changes here
    }
}

ご覧[self adjustViewsForOrientation:self.interfaceOrientation];のとおり、調整メソッドに実際の向きを与えるサブビューコントローラーを呼び出します。fromInterfaceOrientation を使用すると、変更が既に行われているため、誤った方向になります。

私の他の問題は、TabBarController の UISplitviewController でしたが、許容できる方法で動作していませんでした。問題は UIViewControllers の場合と同じです。Orientation Changes を認識しないので、サブクラス化する必要がありますが、100% までは機能しませんでした。Web を検索したところ、cutsom ビルド Splitview の適切なコード例が見つかりました。試してみてください: http://blog.trustedones.com/development/ipad-uisplitviewcontroller-replacement-for-sethidesmasterviewinportrait http://www.trustedones.com/apps/ipad

また、SplitView をポートレート モードに保つので、気に入っていただけると思います。そうです!

この投稿で誰かを助けることができれば幸いです.. Cheers nettz

于 2010-07-25T22:12:56.000 に答える
0

UITabBarController クラス リファレンスの 2 番目の文には、「このクラスはサブクラス化を意図していません」と記載されていることに注意してください。

したがって、このアプローチは機能するかもしれませんが、「正しい」アプローチではないと思います。(私もこの問題を抱えています。)

于 2010-08-28T00:50:42.903 に答える