【问题标题】:interfaceorientation in certain views only仅在某些视图中的界面方向
【发布时间】:2010-09-24 09:59:50
【问题描述】:

我有一个包含 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?

【问题讨论】:

    标签: iphone uiview uiinterfaceorientation uidevice


    【解决方案1】:

    在您的主视图控制器中,覆盖此委托:

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

    现在您的主视图控制器将始终处于横向模式。 并删除您上面提到的所有代码。 你不应该调用“shouldAutorotateToInterfaceOrientation:”方法。

    【讨论】:

    • shouldAutorotate 函数没有被自动调用,所以我添加了一个通知并在收到轮换通知时调用该函数。而且我不想在所有视图中旋转,只在某些视图中。但似乎我没有应用旋转的主要视图受到其子视图的影响。当我旋转主视图时,除状态栏外,所有内容都保持纵向。所以有什么帮助吗????
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-16
    相关资源
    最近更新 更多