2

我在部署信息下将支持的界面方向设置为除了纵向颠倒之外。

我想覆盖 shouldAutorotateToInterfaceOrientation: 用于自定义行为。(即根据条件支持景观)

由于约束,我只有一个视图控制器(自定义视图转换)

这就是我的 appdelegate 中的代码的样子:

self.viewController = [[MyController alloc]initWithNibName:nil bundle:nil];

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;

在 myController.m 中,我覆盖了 shouldAutorotateToInterfaceOrientation:

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

应用程序自动旋转到所有方向,但纵向倒置,并且永远不会调用回调。我在运行时尝试了从 shouldAutorotateToInterfaceOrientation: 更改返回时的建议,但没有成功。为什么?

附带说明一下,在运行时更改旋转支持的最佳方法是什么?

更新:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

被调用。我试着放入

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

没有成功:(

4

2 回答 2

4

用的是ios6

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

在 ios6 上已弃用

于 2012-09-10T08:48:11.207 回答
1

它为我工作:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
    if ([self isKindOfClass:[YourViewController class]]) { // Your view class
        orientations |= UIInterfaceOrientationMaskPortraitUpsideDown;
    }
    return orientations;
}

方向:

orientations |= UIInterfaceOrientationMaskLandscapeLeft;
orientations |= UIInterfaceOrientationMaskLandscapeRight;
于 2013-03-08T11:13:27.767 回答