我正在尝试为我的应用程序的不同子模式实现强制纵向/横向。为此,我有一个UINavigationController作为根控制器,并且每个子模式都有自己的视图控制器,可以是其中之一
@interface iosPortraitViewController : UIViewController
或
@interface iosLandscapeViewController : UIViewController
使用
-(BOOL)shouldAutorotate;
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
-(NSUInteger) supportedInterfaceOrientations;
重载,并根据每个对象的方向类型正确设置。例如,iosLandscapeViewController::supportedInterfaceOrientations返回UIInterfaceOrientationMaskLandscape。
当应用程序中的子模式改变时,使用present / dismissViewController在根视图控制器上呈现相应的视图控制器,这会强制方向重新评估和调用重载的视图控制器类中的函数,并相应地调整自身的方向。
我的问题是,当我们切换到横向模式时,子模式视图的框架偏离了屏幕的左上角,这是它应该在的位置(这是一个显示背景图片的全屏视图)。
出于调试目的,如果我将该子模式的视图控制器更改为iosPortraitViewController,则视图信息为:
size = 480.000000 320.000000
bounds = 0.000000 0.000000 480.000000 320.000000
frame = 0.000000 0.000000 480.000000 320.000000
centre = 240.000000 160.000000
user interaction enabled = 1
hidden = 0
transform = 1.000000 0.000000 0.000000 1.000000 : 0.000000 0.000000
当处于横向模式时,视图信息是:
size = 480.000000 320.000000
bounds = 0.000000 0.000000 480.000000 320.000000
frame = 80.000000 -80.000000 320.000000 480.000000
centre = 240.000000 160.000000
user interaction enabled = 1
hidden = 0
transform = 0.000000 -1.000000 1.000000 0.000000 : 0.000000 0.000000
帧的80,-80原点是我遇到的问题--它应该是0,0。(如果有人能指出它是如何得到80的,-80也将不胜感激-我可以看到X,但不是Y)。
还要注意帧中的w和h是如何交换的,转换是一个旋转转换--从阅读来看,我猜UIWindow (总是处于纵向模式)已经将其应用到根视图控制器的视图转换中了?
我能做些什么来解决这个问题呢?我需要视图控制器视图的框架在正确的位置(即原点在0,0)。我尝试过硬编码,但它似乎不起作用,而且这也不是一个很好的解决方案-我更了解发生了什么,以及如何正确地修复它。
谢谢!
:-)
发布于 2014-04-11 15:08:27
要支持备用横向界面,必须执行以下操作:
从苹果指南到Creating an Alternate Landscape Interface
也可以从指南中找到:
@implementation PortraitViewController
- (void)awakeFromNib
{
isShowingLandscapeView = NO;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
!isShowingLandscapeView)
{
[self performSegueWithIdentifier:@"DisplayAlternateView" sender:self];
isShowingLandscapeView = YES;
}
else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
isShowingLandscapeView)
{
[self dismissViewControllerAnimated:YES completion:nil];
isShowingLandscapeView = NO;
}
}
https://stackoverflow.com/questions/21241282
复制相似问题