OGeek|极客世界-中国程序员成长平台

标题: iOS6 方向 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 22:48
标题: iOS6 方向

我有一个关于 iOS 6 Orientation 的问题。这是我的文件 https://www.dropbox.com/s/f8q9tghdutge2nu/Orientations_iOS6.zip

在这个示例代码中,我想让 MasterViewController 只有一个 Portrait Orientation 而 DetailViewController 有一个 Portrait Orientation,Landscape Orientation。

我知道 iOS 6 的方向是由最上面的 Controller 控制的。

所以我自定义了一个UINavigationController(CustomNavigationController),在该类中设置supportedInterfaceOrientations 和shouldAutorotate。

-(NSUInteger)supportedInterfaceOrientations{
    if([[self topViewController] isKindOfClass:[DetailViewController class]]){
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }else{
        return UIInterfaceOrientationMaskPortrait;
    }
}

-(BOOL)shouldAutorotate
{
    return YES;
}

除了DetailViewController在Landscape Orientation按下返回按钮时,一切都很好,MasterViewController将显示Landscape Orientation。

我可以让 MasterViewController 总是显示 Portrait Orientation 并且 DetailViewController 可以有多个方向吗?

谢谢!



Best Answer-推荐答案


谢谢!布伦南,
我还在我的博客中收集了其他方法。
http://blog.hanpo.tw/2012/09/ios-60-orientation.html

这是另外两种方式。

1.向 UINavigationController 添加类别

    @implementation UINavigationController (Rotation_IOS6)

    -(BOOL)shouldAutorotate
    {
        return [[self.viewControllers lastObject] shouldAutorotate];
    }

    -(NSUInteger)supportedInterfaceOrientations
    {
        return [[self.viewControllers lastObject] supportedInterfaceOrientations];
    }

    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
    }

    @end

2.Swap方法实现(由spoletto制作)

https://gist.github.com/3725118

关于iOS6 方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12546057/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4