各种视图控制器的不同方向?

时间:2014-07-26 10:57:31

标签: ios uiviewcontroller rotation orientation landscape-portrait

所有应用程序都应以纵向显示。但是一些视图控制器应该处于横向模式 - 我希望允许用户以“全屏模式”显示图形。

如何实现?另外一个困难是,当我按下视图控制器并弹出它时,我需要在两种情况下设置方向。

2 个答案:

答案 0 :(得分:1)

如果您使用导航控制器而不是affine transform viewController,如果您的应用处于移植模式。对于全屏和旋转,您可以使用

-(void)setRotationInLandscapeMode:(BOOL)status
{
    if(status)
    {
        [[UIApplication sharedApplication] setStatusBarHidden:status];
        self.navigationController.navigationBar.frame = CGRectOffset(self.navigationController.navigationBar.frame, 0.0, -20.0);
        self.view.transform = CGAffineTransformMakeRotation((M_PI * (90) / 180.0));
        self.view.frame = CGRectMake(0,0, 320,568 );
    }
    else
    {
        [[UIApplication sharedApplication] setStatusBarHidden:status];
        self.view.transform = CGAffineTransformMakeRotation((0));
        self.view.frame = CGRectMake(0,0, 320,568 );
    }
}

并更改viewWillAppear

中的方向
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [self setRotationInLandscapeMode:YES];
}

再次更改为肖像viewWillDisappear

-(void)viewWillDisappear:(BOOL)animated
{

    [super viewWillDisappear:YES];
}

如果你的viewController不在navigationController堆栈中,你也可以考虑supportedInterfaceOrientations

-(NSUInteger)supportedInterfaceOrientations
{

    return UIInterfaceOrientationMaskLandscape;
}

答案 1 :(得分:0)

此密钥可以在Target> YourTarget> General>部署信息>设备方向下的XCode中配置。 enter image description here

必须选择左侧风景风景右侧

我们的AppDelegate中有一个代码,并为屏幕上出现的每个视图控制器调用。

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{

}

在viewcontorllers中编写此代码,您只需要PORTRAIT模式

- (NSUInteger)supportedInterfaceOrientations
{
     return (UIInterfaceOrientationMaskPortrait);
}

在viewcontorllers中编写此方法,您只需要横向模式

- (BOOL)shouldAutorotate
{
     return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskAllButUpsideDown);
    //OR return (UIInterfaceOrientationMaskAll);
}