【问题标题】:iOS 6 rotation to Portrait Upside Down does not work for UITableViewController, iOS 5 is fineiOS 6 旋转到 Portrait Upside Down 不适用于 UITableViewController,iOS 5 很好
【发布时间】:2013-02-27 01:17:10
【问题描述】:

我有一个支持所有四个方向的应用程序,它在 iOS 5 上运行良好。

但是,在 iOS 6 上,我的所有 UIViewController 类都可以正确旋转,但我的 UITableViewController 类不能旋转到 PortraitUpsideDown

应用支持的方向包括所有四个选项。

AppDelegate 支持所有方向:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    //return (UIInterfaceOrientationMaskAll);
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}

我的所有视图类都实现了必要的方法,包括为 iOS 6 引入的方法:

- (NSUInteger)supportedInterfaceOrientations
{
    //return (UIInterfaceOrientationMaskAll);
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}

- (BOOL)shouldAutorotate
{
    BOOL bReturn = [self shouldAutorotateToInterfaceOrientation:self.interfaceOrientation];
    return (bReturn);
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (YES);
}

我能找到的唯一区别是视图的显示方式。

UIViewController

InfoViewController *infoController = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:infoController animated:YES];

UITableViewController

MenuViewController *menuController = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:menuController];
[self presentModalViewController:navigationController animated:YES];

不完全确定实施会对轮换产生什么影响,更不确定该怎么做。

任何指导将不胜感激。

【问题讨论】:

  • 嗯,我刚刚想到我正在呈现一个 UINavigationController,而不是我的 MenuViewController 对象。不确定这是否是实际问题,或者如何将支持的方向与 UINavigationController 对象相关联。

标签: ios ios6 uitableview uiinterfaceorientation


【解决方案1】:

根据我上面的评论,我创建了一个继承自 UINavigationController 的新类,并添加了识别支持的方向的方法。

- (NSUInteger)supportedInterfaceOrientations
{
    //return (UIInterfaceOrientationMaskAll);
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}

然后,当我需要为 UITableViewController presentModalViewController 时,我会创建我的新 RotationNavigationController 类的对象。

似乎解决了我所有的问题。

【讨论】:

  • 这是一个非常省时的答案。它确实有效。我有这个问题好几天了。非常感谢您与我们分享您的答案。
【解决方案2】:
    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
            if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
                return  UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.Portrait.rawValue | UIInterfaceOrientationMask.PortraitUpsideDown.rawValue)
            } else {
                return .All
            }
    }

【讨论】:

    猜你喜欢
    • 2012-12-03
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多