我正在Xcode 4中构建一个iPad应用程序。该应用程序始终显示在横向视图中。为实现这一目标,我尝试了以下方法:
这导致应用程序以横向模式启动,但如果我旋转设备,它仍会改变其方向。另外,当我有一个带有presentationStyle UIPresentationFormSheet的UIViewController时,它会在显示的那一刻旋转到肖像。
在其他一些线程/论坛中,建议为UIViewController创建一个类别并重写
-(UIDeviceOrientation)interfaceOrientation;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
要始终旋转到设备方向(LandscapeLeft)或特别是LandscapeLeft,也要旋转到无AutoRotate,除非您旋转到LandscapeLeft。
当我像这样设置这些功能时(或者例如根本不允许旋转),应用程序始终以纵向模式显示,并且不会旋转,甚至不会旋转到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上的原始窗口,但这不能改变,并且每个线程/论坛都说该特定设置是/不应该是问题。
答案 0 :(得分: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])
}