1

私の質問はiOS6で答えられているように感じます:supportedInterfaceOrientationsが機能していません(呼び出されますが、インターフェイスはまだ回転しています)が、応答を実装する方法を理解するのに十分な知識がありません。

iOS6を使用してタブ付きアプリケーションを作成していますが、ビューコントローラーの1つを回転させ、残りのコントローラーをそのままにしておく必要があります。使用する必要があることは理解していますが、使用supportedInterfaceOrientations方法や使用場所がわからず、Appleのドキュメントを解読できませんでした。に関連する場合は、のUITabBarControllerルートビューコントローラとしてが設定されAppDelegateます。

助けてくれてありがとう。

4

3 に答える 3

2

この問題は私を一週間殺していた。私はまったく同じ状況にあり、1つのビューに対しても回転できるようにしたかっただけです。タブ付きアプリでそれを回避する方法は、オリエンテーション通知に登録することです。TabController(およびその他のsuperView)と回転するVCのshouldAutoRotateに対してNOを返します。次に、viewWillAppearで通知を登録します。

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)name:UIDeviceOrientationDidChangeNotification
          object:[UIDevice currentDevice]];

そして、呼び出される関数は次のようになります。

- (void) orientationChanged:(NSNotification *)note
{
    UIDevice * device = note.object;
    switch(device.orientation)
    {
        case UIDeviceOrientationPortrait:
            break;

        case UIDeviceOrientationPortraitUpsideDown:
            break;
        case UIDeviceOrientationLandscapeLeft:
            if(viewHasAppeared==true){
                [self performSegueWithIdentifier:@"firstToLandscape" sender:self];}
            break;
        case UIDeviceOrientationLandscapeRight:
            if(viewHasAppeared==true){
                [self performSegueWithIdentifier:@"firstToLandscape" sender:self];}
            break;
        default:
            break;
    };
}

-ビューが実際に表示されるまでセグエできないため、ViewDidAppear内にブール値を配置します。

ランドスケープモードで変更するビューがタブ付きのViewControllerでない場合、それを処理する最良の方法は、そのビューでAutoRotationを許可し、willAnimateで次のようにVCを閉じることです。

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
    {
       [self dismissViewControllerAnimated:YES completion:nil];     
    }
}

タブ付きのビューの場合は、そのビューでも向きの変更を登録するだけです。ただし、ビューを離れるときは、必ずorientationChange通知を削除してください。そうしないと、他のviewControllerからもランドスケープに移行することになります。

また、別のタブに移動する場合は、tabBarControllerデリゲートを実装し、次のようにオブザーバーを削除する必要があります。

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if(![NSStringFromClass([viewController class])isEqualToString:@"FirstViewController"])
    {
            [[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];             
    }

}
于 2013-01-22T21:07:56.683 に答える
1

supportedInterfaceOrientationsUITabBarControllerサブクラスに実装します。これは、最初のViewControllerが縦向きから自動回転しない例です。

- (NSUInteger)supportedInterfaceOrientations {
    if ( self.selectedIndex == 0 )
        return UIInterfaceOrientationMaskPortrait ;
    else
        return UIInterfaceOrientationMaskAll ;
}

ただし、View Controller#2(インデックス1)に切り替え、横向きに回転して、View Controller#1に戻すと、View Controller#1が横向きで表示されます。私は解決策を探しています。

于 2013-01-22T20:54:49.540 に答える
-1

これを実現する簡単な方法は、ビューを適切にロードし、viewDidLoad:メソッドの最後に変換を使用してUIView全体を回転させることです。

[self.view setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
于 2013-01-22T20:52:23.377 に答える