仅在某些视图中的界面方向

发布于 2024-09-25 05:26:55 字数 896 浏览 0 评论 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?

I have a Main View that contatins uitableview, and I am pushing another view when the user taps on a row. I want only the child views to rotate and have written code for that. But the problem is once I push the view, it also enables the orientation on the Main View.

When I rotate the main view to the left, the statusbar also changes to the left. I have not applied any orientation on the Main View. I have done the following on the MainView but code still the status bar doesn't change.

 -(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];
        }
    }

}

How can I disable interfaceOrientation in the Main view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稳稳的幸福 2024-10-02 05:26:55

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

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

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

in your main view controller, override this delegate:

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

Now your main view controller will always be in landscape mode.
And remove all your code which you mentioned above.
you should not call the "shouldAutorotateToInterfaceOrientation:" method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文