横向定向屏幕中的ios横向屏幕结果

时间:2017-01-11 15:44:18

标签: ios objective-c iphone

when first entry, the result like this

App into the background and back, the orientation is normal

这是ViewController的代码:

DDYLoveAutoHallViewController *autoHallViewController = [[DDYLoveAutoHallViewController alloc] initWithEvent:room.currentEventID type:AHRoom_System];
[self presentViewController:autoHallViewController animated:YES completion:nil];

我不知道为什么,该项目是一个老垃圾,它以前支持iOS5。

2 个答案:

答案 0 :(得分:1)

如果不了解你如何管理布局,很难给出确切的原因,导致你的问题,但是,我可以建议你一些小建议:

  • 尝试重新检查 - (void)viewDidLayoutSubviews中的方向,然后您可以从那里重新定位事物。 (可能它会起作用并解决你的问题,但它不是非常干净的解决方案,因为可能会被称为几次,知道这可以使它更清洁)

  • 通常使用布局生命周期的方法,来检测出错的地方。在iOS上进行布局的现代化方式更深入。 (更好的解决方案)

答案 1 :(得分:0)

如果没有关于您的具体问题的更多详细信息,以及您如何检测和调整方向,很难理解确切的问题,但这里有一些观察,我使用iOS 5.x(及更早版本) ,应用程序,可能会指向正确的方向:

[1] iOS的早期版本在实际查询硬件以确定方向和应用程序帧大小信息之前设置了一些默认值。

a)在初始化期间,最初的方向设置为PORTRAIT - 以及纵向方向框架尺寸。 (如果您的设备处于横向方向,则此错误 - 因此请勿使用此初始信息)。 (从之前的“仅iPhone日期”遗留下来 - 我猜)

b)在“ViewDidLoad”和“applicationDidBecomeActive”时间范围内(至少对我的应用程序来说 - 可能 - 取决于加载时间等),这仍然是不正确的。

c)稍后通过“didChangeStatusBarOrientation方法调用”产生正确的方向。您可以将此信息与Window.frame.size信息一起使用,以显示具有正确大小的正确图像。 这实际上是指示方向请求现在是正确的触发器。 一个策略可能是:在收到“didChangeStatusBarOrientation”消息之前,不要尝试显示任何内容。

[2]非代码解决方案:(使用设置:支持的界面方向)

a)如果应用程序设计为始终以横向方向工作,请确保这反映在应用程序设置/ info.plist中。我建议只允许1个“支持的界面方向”,即横向,并且所有视图都会反映出横向大小和方向。(如果您的代码没有专门设置或做任何有方向的东西,那么这可能是通过设置所有内容的解决方案“仅景观”。否则此选项可能无济于事。)

[3]最后解决方案:

a)如果您可以更高版本的iOS版本,iOS6及更高版本会在初始化周期的早期初始化方向和帧大小,因此问题可能会因此而消失。

以下是一些用于发现此问题的代码,以及下面的输出(使用原始ipad作为示例,在这种情况下......运行iOS 5.1.1 - 以横向和方向开始未更改)

-(void) OrientationAndScreenSizeHELPER : (NSString *)fromObject
{
    //from:

    // NSLog(@"%s:%d someObject=%@", __func__, __LINE__, someObject);


    CGRect appFrame = [[UIScreen mainScreen ]applicationFrame];//using frame so status bar is not part of calculations.

    appFrame = [[self.viewController view]frame];//using frame so status bar is not part of calculations.

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

    NSLog(@"orientation[%ld] at time[%@]    width[%ld] height[%ld]",
      (long)orientation,
      fromObject,
      (long int)appFrame.size.width,
      (long int)appFrame.size.height);

}

**Output:**
orientation[1] at time[ViewDidLoad Orientation]    width[768] height[1024]
orientation[1] at time[applicationDidBecomeActive]    width[768] height[1024]
orientation[3] at time[didChangeStatusBarOrientation]    width[1024] height[768]
相关问题