以编程方式更改iPhone中的设备方向

以编程方式更改iPhone中的设备方向

问题描述:

我有基于导航的应用程序,当我点击根视图中的任何行时,下一个视图应该以横向模式进入。

I have navigation based app, when I click on any row in root view, the next view should come in Landscape mode.

我无法找到实现此方法的正确方法。我试过的是:

I am not able to find a proper way to implement this. What I tried is:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {   
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

但这不起作用。视图应仅在横向模式下打开(而不是在用户旋转时)。谁能帮我。谢谢

But this is not working. The view should open only in Landscape mode (not when user rotate it). Can any one help me. Thanks

我的沙盒应用程序:
https://github.com/comonitos/programatical_device_orientation

解决方案很简单:

    BOOL rotated;

实现中(m文件):
1.重写

in implementation (m file): 1. rewrite

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    return rotated;
    }

2来电[自我设置]

2 call [self setup]

    -(void) setup { 
    rotated = YES; 
    [[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft]; 
    rotated = NO; 
    }