首页 文章

旋转Xcode 4的iPad停止屏幕

提问于
浏览
2

我正在Xcode 4中构建一个iPad应用程序 . 该应用程序总是显示在横向视图中 . 为实现这一目标,我尝试了以下方法:

  • 在目标摘要屏幕中,我仅选择Landscape Left作为支持的设备Orentation .

  • 在目标信息屏幕/ Info.plist中将支持的界面方向(iPad)设置为横向(左主页按钮)

这导致应用程序以横向模式启动,但如果我旋转设备,它仍会改变其方向 . 此外,当我有一个带有presentationStyle UIPresentationFormSheet的UIViewController时,它会在显示的那一刻旋转到肖像 .

在其他一些线程/论坛中,建议为UIViewController创建一个类别并重写

-(UIDeviceOrientation)interfaceOrientation;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;

要始终旋转到设备方向(LandscapeLeft)或特定的LandscapeLeft,除非您旋转到LandscapeLeft,否则也不要旋转到AutoRotate .

当我像这样设置这些功能时(或者例如根本不允许旋转),应用程序始终以纵向模式显示,并且不会旋转,甚至不会旋转到LandscapeLeft . 让应用程序以横向模式启动的唯一方法是,无论interfaceOrientaton是什么,我都允许旋转 .

有谁知道我怎么解决这个问题?

我实施的类别:

@implementation UIViewController(Extends)

-(UIDeviceOrientation)interfaceOrientation
{

    return [[UIDevice currentDevice] orientation];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        return YES;
    else
        return NO;
}

@end

我可以找到定义纵向方向的唯一地方是MainWindow.xib上的原始窗口,但这不能改变,并且每个线程/论坛都说该特定设置是/不应该是问题 .

1 回答

  • 1

    据我所知,你采取的步骤应该防止界面旋转 .

    您始终可以尝试覆盖在应用的每个视图控制器中执行方向的调用 . 这至少应该为你提供旋转发生的线索 . 之后断点可能会告诉你更多 .

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
       NSLog( @"will rotate to orientation %d in %@", interfaceOrientation, NSStringFromClass([self class])
    }
    
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
       NSLog( @"did rotate from orientation %d to %d in %@", fromInterfaceOrientation, [self interfaceOrientation], NSStringFromClass([self class])
    }
    

相关问题