我有一个应用程序,其中一个标签栏控制器有 3 个标签,每个标签都有一个视图控制器。视图控制器 1 和 2 仅支持纵向模式,但选项卡 3 中的视图控制器支持所有方向 - 纵向、横向左侧、横向右侧和纵向倒置。对于选项卡 3,我们必须在设备处于纵向模式时显示特定视图,而在设备处于横向模式时显示另一个视图。
如果设备处于纵向模式并且用户单击选项卡 3,则视图在纵向模式下正确加载,然后如果我们将设备旋转到横向模式,横向视图将正确加载。
但是如果我们在选项卡 1 本身中将设备设置为横向模式,然后单击选项卡 3 ,则会出现问题,然后它显示屏幕以横向模式显示,但它显示为纵向视图。
当我试图通过 NSLogging 在委托方法中找出原因时
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
interfaceOrientation 的值为 1,即 UIInterfaceOrientationPortrait 并且控件进入为纵向模式编写的 if 条件
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
当我尝试在同一个委托方法中打印 UIDevice 方向的值时
UIDeviceOrientation interfaceOrientation = [UIDevice currentDevice].orientation;
NSLog(@" device orientation %u", interfaceOrientation);
控制台中打印的值是 4- 这是 UIDeviceOrientationLandscapeRight。
所以界面方向是 UIInterfaceOrientationPortrait 但设备方向是 UIDeviceOrientationLandscapeRight。
还有一件事,现在如果我将设备旋转到纵向模式,然后切换到横向模式,则会显示正确的横向视图,并且应用程序开始正常运行。
所以问题是,如果我在横向模式下加载选项卡 3,它不会正确加载,但是如果我们进入纵向模式,然后旋转到横向,如果从那里可以正常工作。
如果有人可以提供一些有用的建议,为什么这种行为会非常有益。
谢谢