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

时间:2010-12-30 03:37:32

标签: iphone

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

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

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

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

4 个答案:

答案 0 :(得分:2)

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

解决方案很简单:

接口(h文件)中的

    BOOL rotated;
实现中的

(m文件): 1.重写

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

2调用[自我设置]

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

答案 1 :(得分:0)

你可以强制你的设备改变方向.......在视图中使用魔术线将出现

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeRight];

All the Best ..

答案 2 :(得分:0)

尝试在横向模式及其视图控制器中设计视图,并在

中设计
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {   
   .....
}

纵向方向返回否,横向方向返回YES 这将以横向模式显示您的视图。

答案 3 :(得分:0)

以下是基于横向视图的应用中的一些代码:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{

    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
        return YES;
    }
    else {
        return NO;
    }

}

将其置于基于横向的视图控制器中,使其仅以横向模式显示,并在横向左侧和横向右侧之间切换。你还需要你的xib是基于风景的。

相关问题