首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >理解iOS 6接口方向的变化

理解iOS 6接口方向的变化
EN

Stack Overflow用户
提问于 2012-10-08 09:15:09
回答 2查看 16.2K关注 0票数 23

补充道:,我看到我的问题经常被浏览而没有得到支持,所以我决定你们不会得到你们搜索的东西。重定向到有关于How to handle orientation changes in iOS6的很好答案的问题

对定位更改的具体要求:Restricted rotation

欢迎投票:)

我已经创建了一个新的项目,从主细节模板,并试图开始它的景观定位。如你所知

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

方法是不推荐的,我们必须使用

- (NSUInteger)supportedInterfaceOrientations

和/或

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

这是我的密码:

代码语言:javascript
复制
- (NSUInteger)supportedInterfaceOrientations {
    NSLog(@"supported called");
    return UIInterfaceOrientationMaskAll;//Which is actually a default value
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    NSLog(@" preferred called");//This method is never called. WHY?
    return UIInterfaceOrientationLandscapeRight;
}

正如您所看到的,我正在尝试以首选的方法返回景观方向,但从来没有调用过它。附注:文件规定:

讨论了在显示视图控制器全屏时,系统调用该方法的方法。当视图控制器支持两个或多个方向时,实现此方法,但内容在其中一个方向中显示得最好。 如果您的视图控制器实现了这个方法,那么当显示它时,它的视图将以首选的方向显示(尽管它以后可以旋转到另一个受支持的旋转方向)。如果不实现此方法,系统将使用状态栏的当前方向显示视图控制器。

因此,问题是:为什么从来不调用prefferredOrientation方法?我们应该如何处理不同控制器的不同方向?谢谢!P.S不要把问题标记为重复。我调查过所有类似的问题,但他们对我的问题没有答案。

EN

回答 2

Stack Overflow用户

发布于 2013-02-13 13:24:19

如果您希望在景观模式下启动模式视图,只需将此代码放在呈现视图控制器中即可。

代码语言:javascript
复制
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    UIInterfaceOrientation orient = [[UIApplication sharedApplication] statusBarOrientation];
    if (UIInterfaceOrientationIsLandscape(orient)) {
        return orient;
    }

    return UIInterfaceOrientationLandscapeLeft;
}

然后,像往常一样呈现这个控制器。

代码语言:javascript
复制
UIViewController *vc = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self.navigationController presentViewController:vc animated:YES completion:^{}];
票数 8
EN

Stack Overflow用户

发布于 2015-03-24 13:30:17

有一个非常简单的答案:您只能更改或修复模态呈现视图控制器的接口方向。如果这样做,即在接口构建器(或导航控制器方法)中使用当前模式segue,则可以使用

代码语言:javascript
复制
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait; // for example else an addition of all allowed
}

当您只在导航控制器上推送视图控制器时,此事件不会触发。所以:你没有后退按钮,你需要一个

代码语言:javascript
复制
[self dismissViewControllerAnimated:YES completion: ^(void) {

    }];

关闭它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12778636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档