10

我看过几个类似问题的答案,但没有一个答案有效。我有一个应用程序,除了我拥有的一个照片查看器之外,我需要所有肖像。在目标菜单的支持方向部分中,我只有纵向。我如何强制我的一种观点是风景。它正在从导航控制器推入堆栈,但我正在使用情节提要来控制所有这些。

4

3 回答 3

14

由于答案似乎隐藏在问题的评论中,并且由于 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 只是肖像,应用程序永远不会想到进入横向。

于 2014-03-11T00:19:57.447 回答
2

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

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

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
        return orientation==UIInterfaceOrientationMaskLandscape;
    }

或者

在您的应用委托中尝试此方法

- (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 字符串值并在下一个视图控制器中执行相同的步骤。

于 2013-08-26T06:25:05.713 回答
0

让我们试试这段代码:

    [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);
于 2014-11-21T11:14:40.137 回答