我正在构建一个模板应用程序。我在设备旋转/方向上遇到了一些问题。我在我的appDelegate didFinishLaunching如下:Objective-c设备方向
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
,并在我的VC viewDidLoad中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
...
//add the title bar
titleBar = [[OAI_TitleBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 1024.0, 50.0)];
titleBar.titleBarTitle = @"OAI Template";
titleBar.hasAccount = YES;
titleBar.hasReset = YES;
titleBar.hasHome = YES;
[titleBar buildTitleBar];
[self.view addSubview:titleBar];
这是我deviceOrientationDidChange方法:
//rotate the vc view
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
[self.view setFrame:CGRectMake(0.0, 0.0, 1024.0, 768.0)];
} else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
[self.view setFrame:CGRectMake(0.0, 0.0, 768.0, 1024.0)];
}
//call the rotation management methods of various classes
[titleBar adjustForRotation:orientation];
}
这工作正常,当我旋转设备,意见调整如预期。但是当应用程序启动时,x,y坐标是错误的 - 当我以纵向方式启动时记录框架时,VC视图的框架为{{0,20},{768,1004}},当以横向模式启动时{{20,0},{748,1024}}
横向和纵向标题栏框架{{20,0},{748,1024}}(与我编码时一样)。
但是,我在模拟器和我的设备上看到的是截然不同的。你应该看到的是一个黑色的条(顶部有50个像素左右),左边有一个标志,随后是一些按钮,然后应用标题向右对齐。正如你可以从下面的图片看到的,当应用程序以任一方向启动时,它的开放x/y坐标不会在0/20附近。任何帮助,将不胜感激。
看起来对我来说,当应用程序在横向上启动时,它将显示为纵向,当它以纵向显示时,尽管显示是正确的,但大约在20.0f左右。任何帮助,将不胜感激。
好吧,所以肖像解决方案很明显,它应该重置为0,20,1004,768,但我仍然有景观视图的问题,虽然我现在可以看到一个标题栏,VC视图本身是从设备的左侧边缘加载约200.0英寸的内容。 – PruitIgoe