Iphone 一个视图控制器ios的强制横向

Iphone 一个视图控制器ios的强制横向,iphone,ios,uinavigationcontroller,orientation,viewcontroller,Iphone,Ios,Uinavigationcontroller,Orientation,Viewcontroller,我已经看过几个类似问题的答案,但没有一个有效。我有一个应用程序,除了一个照片查看器之外,我需要它的一切。在目标菜单的支持方向部分,我只有纵向。我如何强迫我的一个观点是风景。它被从导航控制器推到堆栈上,但我使用故事板来控制所有这些。是的,这是可能的,您可以使用以下代码: -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)windo

我已经看过几个类似问题的答案,但没有一个有效。我有一个应用程序,除了一个照片查看器之外,我需要它的一切。在目标菜单的支持方向部分,我只有纵向。我如何强迫我的一个观点是风景。它被从导航控制器推到堆栈上,但我使用故事板来控制所有这些。

是的,这是可能的,您可以使用以下代码:

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
        return UIInterfaceOrientationMaskLandscape;
    }

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
        return orientation==UIInterfaceOrientationMaskLandscape;
    }
    [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
self.navigationController.view.center = CGPointMake(([UIScreen mainScreen].bounds.size.width/2), [UIScreen mainScreen].bounds.size.height/2);
CGFloat angle = 90 * M_PI / 180;
self.navigationController.view.transform = CGAffineTransformMakeRotation(angle);
self.navigationController.view.bounds = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.height , [UIScreen mainScreen].bounds.size.width);

在应用程序代理中尝试此方法

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if (sglobalorientation isEqualToString:@"AllOrientation"]) {
        return UIInterfaceOrientationMaskLandscape;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}
在移动到该横向视图控制器之前,需要将变量值sglobalorientation更改为该字符串值AllOrientation

并且在您的横向视图控制器中,使用此代码将在您的视图中显示

 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
    DigitalSignatureViewController *digisign = [[DigitalSignatureViewController alloc]init];
    [self presentModalViewController:digisign animated:NO];
    [self dismissModalViewControllerAnimated:NO];
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return NO;
}

再次,当您移动到下一个视图控制器时,请更改sglobalorientation字符串值,并在下一个视图控制器中执行相同的步骤。

由于答案似乎隐藏在问题的注释中,并且由于ArunMak的答案相当混乱,因此我只提供我发现的:

我所要做的就是将此函数添加到视图的自定义UIViewController子类中:

- (NSUInteger)supportedInterfaceOrientations {
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        // iPad: Allow all orientations
        return UIInterfaceOrientationMaskAll;
    } else {
        // iPhone: Allow only landscape
        return UIInterfaceOrientationMaskLandscape;
    }
}
请注意,该项目需要允许所有方向(即:纵向、横向左侧、横向右侧-但决不能在iPhone上倒置!)

如果要将某些或大多数视图限制为纵向视图,则需要在每个视图控制器中实现上述方法(或为其使用一个通用的超类,并从中对所有其他视图进行子类化)-如果将Info.plist中的设备方向限制为仅纵向视图,该应用程序甚至从未想过进入风景区。

让我们试试下面的代码:

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
        return UIInterfaceOrientationMaskLandscape;
    }

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
        return orientation==UIInterfaceOrientationMaskLandscape;
    }
    [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
self.navigationController.view.center = CGPointMake(([UIScreen mainScreen].bounds.size.width/2), [UIScreen mainScreen].bounds.size.height/2);
CGFloat angle = 90 * M_PI / 180;
self.navigationController.view.transform = CGAffineTransformMakeRotation(angle);
self.navigationController.view.bounds = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.height , [UIScreen mainScreen].bounds.size.width);

应自动旋转
[[UIApplication sharedApplication]设置状态BaroOrientation:UIInterfaceOrientation和scapeRight],Nadaw您的目标是什么版本的iOS?抱歉,iOS 6。。。我也试过:
http://stackoverflow.com/questions/14633213/force-portrait-orientation-while-pushing-from-landscape-view-controller
另外,我读过你的书。你能帮助我是我的荣幸!还有,谢谢!这句话让我一夜没睡。“-(NSUInteger)应用程序:(UIApplication*)应用程序支持的interfaceorientationsforwindow:(UIWindow*)窗口”毫无意义。相反,在ViewController中将其实现为“-(NSInteger)supportedInterfaceOrientations”。此解决方案是错误的。尝试编辑字段时,键盘不会旋转。当然,系统警报也会发生同样的情况。状态栏也不工作。