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 回答