0

uitableview を含むメイン ビューがあり、ユーザーが行をタップすると別のビューをプッシュしています。子ビューのみを回転させ、そのためのコードを記述したいと考えています。しかし問題は、ビューをプッシュすると、メイン ビューの向きも有効になることです。

メイン ビューを左に回転すると、ステータス バーも左に変わります。メイン ビューに向きを適用していません。MainView で次のことを行いましたが、コードはまだステータス バーが変わりません。

 -(void) viewDidLoad
{
     [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
     [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(receivedRotate:) name: UIDeviceOrientationDidChangeNotification object: nil];
 }

-(void) receivedRotate: (NSNotification*) notification
 {
    UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];

    if(interfaceOrientation != UIDeviceOrientationUnknown)
    {
        if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft)
        {
           [self shouldAutorotateToInterfaceOrientation:interfaceOrientation];
        }
    }

}

メイン ビューで interfaceOrientation を無効にするにはどうすればよいですか?

4

1 に答える 1

1

メイン ビュー コントローラーで、このデリゲートをオーバーライドします。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation; // Override to allow rotation. Default returns YES only for UIDeviceOrientationPortrait
{
    if((toInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
        return YES;
    return NO;
}

これで、メイン ビュー コントローラーは常に横向きモードになります。上記のコードをすべて削除します。「shouldAutorotateToInterfaceOrientation:」メソッドを呼び出さないでください。

于 2010-09-24T11:14:07.603 に答える