3

我有一个支持旋转到横向模式的视图控制器(VC1)。但是在下一个视图(VC2)中,我只想让它以纵向模式出现,我的意思是如果用户在横向模式下的 VC1 上并进入 VC2,那么它的视图会根据横向边界设置它们的框架。我不希望这样,我希望视图应该旋转 90 度,就像用户已经在 VC2 纵向模式下然后将设备上的方向更改为横向且 VC2 不支持自动旋转的情况一样。

我注意到只有当父视图控制器也不支持自动旋转时才会发生这种情况。如果父视图不支持自动旋转,则在横向模式下推送或呈现时,子视图将旋转 90 度。

4

1 回答 1

0

我解决这个问题的方法是使整个项目仅显示为纵向,并且在我需要旋转的视图上,我将在 viewDidLoad 中设置一个 NSNotifier,如下所示。

NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];

然后我会像这样处理方向的变化:

-(void)handleOrientationDidChange:(NSNotification *)notification
{
UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
    // Change view frame to fit landscape mode and rotate
} else {
    // Reset view frame to fit portrait mode and rotate back to orignal position
}

我不知道这是否符合您的需求,但这是我如何处理 VC1 需要旋转但 VC2+ 不需要旋转的情况。

于 2012-12-14T09:06:10.190 回答