相关疑难解决方法(0)

如何仅在Swift中将一个视图控制器的方向锁定为纵向模式

由于我的应用得到了所有方向的支持.我想只将肖像模式锁定到特定的UIViewController.

(例如,假设它是Tabbed应用程序,当SignIn View以模态方式出现时,我只想将SignIn View设置为纵向模式,无论用户如何旋转设备或当前设备方向如何)

portrait uiviewcontroller device-orientation swift

81
推荐指数
8
解决办法
8万
查看次数

如何在iOS 7中以编程方式设置设备方向?

我正在使用AutoLayout在iPad应用程序上工作,如果用户启用某种模式("抬头"模式),我想只支持纵向(或纵向颠倒)方向,此外,如果设备在风景,我想自动切换到纵向模式.

在顶视图控制器中,我有以下内容:

- (NSUInteger) supportedInterfaceOrientations {
    if (self.modeHeadsUp) {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}

- (BOOL) shouldAutorotate {
    return TRUE;
}
Run Code Online (Sandbox Code Playgroud)

基于我在其他地方看到的答案,答案似乎是我应该使用"application setStatusBarOrientation".因此,在用户选择"抬头"模式的方法中,我包括:

    UIApplication *application = [UIApplication sharedApplication];
    [application setStatusBarOrientation:UIInterfaceOrientationPortrait
                                animated:YES];
Run Code Online (Sandbox Code Playgroud)

但是,这根本就没有做任何事情.虽然我可以物理移动设备以使其旋转为纵向,但它不会自动移动.

实际上,在运行上面的代码后尝试以横向模式尝试以编程方式设置方向时,当我使用以下代码查询应用程序"statusBarOrientation"时,它对于横向保持为"4":

UIApplication *application = [UIApplication sharedApplication];
int orientation = [application statusBarOrientation];
self.movesTextView.text = [NSString stringWithFormat:@"ORIENTATION %d", orientation];
Run Code Online (Sandbox Code Playgroud)

好像autolayout可能没有被setStatusBarOrientation触发,所以我试图在之后添加这个代码,没有效果:

    [super updateViewConstraints];
    [self.view updateConstraints];
Run Code Online (Sandbox Code Playgroud)

我意识到Apple希望将设备方向放在用户手中.但是,我希望能够在不进行"抬头"模式时支持横向模式.

我错过了能够强制改变方向的东西吗?

xcode autorotate ios autolayout ios7

71
推荐指数
4
解决办法
10万
查看次数

UINavigationController强制旋转

我的应用程序主要是肖像,但有一个视图需要横向方向.

我的观点包含在UINavigationController中,显然这是导致此问题的原因.

除了一个之外的所有UIViewControllers都有:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Run Code Online (Sandbox Code Playgroud)

需要Landscape的UIViewController有这样的:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)

现在,当用户到达横向UIViewController时会发生什么,它以纵向显示.然后,用户可以旋转他们的手机,并按照我想要的方式显示在风景中(锁定到风景).然后用户继续前进到肖像UIViewController,同样的事情发生:它从横向开始,然后他们旋转他们的手机,它再次成为肖像(并锁定到肖像).

似乎UIViewControllers之间允许方向锁定,但是以某种方式阻止了自动旋转/以编程方式更改方向.

如何强制手机更新到正确的方向?

有一个临时解决方案:我可以检测设备的方向并显示一条消息,要求他们旋转设备,如果它不正确,但这不是最佳的.

iphone objective-c uinavigationcontroller ios ios5

18
推荐指数
2
解决办法
2万
查看次数

故事板中新视图控制器的类

在我的故事板中,我拖动了一个新的视图控制器.我的故事板现在有两个视图控制器:我创建文件时出现的主要视图控制器和拖动的视图控制器.

当我进入'助手编辑器'并选择主视图控制器时,我得到了ViewController.h类.但是当我选择另一个控制器时,我得到的是UIViewController.h,这是一个Apple文件.

如何为每个View Controller链接/创建这些类?有没有自动化的方法来做到这一点,或者我做得不对.

iphone xcode objective-c ios

11
推荐指数
1
解决办法
1万
查看次数

如何只制作一个子视图?

我知道有一个samilar问题只有一个VIEW横向模式,在我问这个之前我已经仔细考虑过了.

我的应用程序中有一个名为webview的WKWebview,webview有一个名为player的子视图.我使用webview加载网页,播放器播放视频.

默认情况下,播放器在webview的右下角进行压缩,我想在单击播放器的展开按钮时将播放器扩展为横向.

因为webview和播放器在WebViewController.swift中是defind,这就是说在同一个控制器中.我怎样才能让玩家子视图成为风景?

xcode subview uiviewcontroller uiview swift3

5
推荐指数
1
解决办法
184
查看次数