简体   繁体   English

优化最新的iPad Pro Simulator

[英]Optimization for newest iPad Pro Simulator

I have installed the newest Xcode 7.1 beta and trying to run my project on the iPad Pro Simulator. 我安装了最新的Xcode 7.1 beta并尝试在iPad Pro Simulator上运行我的项目。 Everything is right and all of the features work correct. 一切都是正确的,所有功能都正常。

But I have an issue with the screen size... 但我的屏幕尺寸有问题......

On the main screen of application I run the next log: 在应用程序的主屏幕上,我运行下一个日志:

NSLog(@"%f", self.view.bounds.size.width);

I have 1024 for landscape orientation. 我有1024个横向方向。 But when I create a new application in Xcode 7.1 and run the same code on the main screen I get another value: 1366. 但是当我在Xcode 7.1中创建一个新的应用程序并在主屏幕上运行相同的代码时,我得到另一个值:1366。

Today I plan to find diffs between project files created in old Xcode (6.4) and newest beta 7.1 using Araxis Merge. 今天我计划使用Araxis Merge在旧Xcode(6.4)和最新beta 7.1中创建的项目文件之间找到差异。

Do you now how to fix this issue for the my old project? 你现在如何为我的旧项目解决这个问题?

I may be way off here, but I was having a similar problem with the iPad Pro simulator: it kept giving me the standard 1024*768 point resolution. 我可能会离开这里,但我遇到了与iPad Pro模拟器类似的问题:它一直给我标准的1024 * 768点分辨率。 After some digging, I realized that I was using the standard iPad launch image (since there is no iPad Pro version in the asset catalog), which restricted my screen to remain 1024*768 points. 经过一番挖掘后,我意识到我正在使用标准iPad发布图像(因为资产目录中没有iPad Pro版本),这限制了我的屏幕保持1024 * 768点。 Once I introduced a launch storyboard, everything fell into place, and my app launched with the correct, 1366*1024 point size. 一旦我介绍了发布故事板,一切都已落实到位,我的应用程序以正确的1366 * 1024点大小启动。

TL;DR: It appears that the view hierarchy is not adjusted for the iPad Pro screen size until viewWillLayoutSubviews: and viewDidLayoutSubviews: is invoked. TL; DR viewDidLayoutSubviews:在调用viewWillLayoutSubviews:viewDidLayoutSubviews:之前,看来视图层次结构未针对iPad Pro屏幕大小进行调整。 When this is invoked by the layout system depends on the construction of your view hierarchy. 当布局系统调用它时,取决于视图层次结构的构造。


In updating my app for iPad Pro I'm also seeing similar behavior. 在为iPad Pro更新我的应用程序时,我也看到了类似的行为。 Therefore I took a deeper look at the view controller lifecycle events to see what was happening in both my existing project as well as a new project. 因此,我深入研究了视图控制器生命周期事件,以查看现有项目和新项目中发生的情况。

For a brand-new project, using a view controller that only has a navigation bar (placed just below the status bar) and a primary view (that takes up the remainder of the space, with auto-layout turned on, in landscape mode a la the following screenshot: 对于一个全新的项目,使用仅具有导航栏(位于状态栏下方)的视图控制器和主视图(占用剩余空间,打开自动布局,在横向模式下)以下截图:

具有导航栏和自动布局的示例视图控制器

I'm seeing the following output from the console for the view controller lifecycle: 我在视图控制器生命周期的控制台中看到以下输出:

-[ViewController viewDidLoad] self.navigationBar: .frame: {{0, 20}, {1024, 44}}; .bounds: {{0, 0}, {1024, 44}}
-[ViewController viewDidLoad] self.primaryView: .frame: {{0, 64}, {1024, 704}}; .bounds: {{0, 0}, {1024, 704}}

-[ViewController viewWillAppear:] self.navigationBar: .frame: {{0, 20}, {1024, 44}}; .bounds: {{0, 0}, {1024, 44}}
-[ViewController viewWillAppear:] self.primaryView: .frame: {{0, 64}, {1024, 704}}; .bounds: {{0, 0}, {1024, 704}}

-[ViewController viewWillLayoutSubviews] self.navigationBar: .frame: {{0, 20}, {1024, 44}}; .bounds: {{0, 0}, {1024, 44}}
-[ViewController viewWillLayoutSubviews] self.primaryView: .frame: {{0, 64}, {1024, 704}}; .bounds: {{0, 0}, {1024, 704}}

-[ViewController viewDidLayoutSubviews] self.navigationBar: .frame: {{0, 20}, {1366, 44}}; .bounds: {{0, 0}, {1366, 44}}
-[ViewController viewDidLayoutSubviews] self.primaryView: .frame: {{0, 64}, {1366, 960}}; .bounds: {{0, 0}, {1366, 960}}

-[ViewController viewDidAppear:] self.navigationBar: .frame: {{0, 20}, {1366, 44}}; .bounds: {{0, 0}, {1366, 44}}
-[ViewController viewDidAppear:] self.primaryView: .frame: {{0, 64}, {1366, 960}}; .bounds: {{0, 0}, {1366, 960}}

From what I can see here, the view starts out with a width of 1024 points but once 'viewDidLayoutSubviews' is executed, the appropriate size has been determined (1366 points). 从我在这里看到的,视图开始的宽度为1024点,但一旦执行'viewDidLayoutSubviews',就确定了合适的大小(1366分)。

In my own project for one screen which is using a split-view controller, I can see similar behavior: 在我自己的一个使用分割视图控制器的屏幕项目中,我可以看到类似的行为:

-[XYZViewController viewDidLoad] self.navigationBar: .frame: {{0, 20}, {1024, 44}}; .bounds: {{0, 0}, {1024, 44}}

-[XYZViewController viewWillLayoutSubviews] self.navigationBar: .frame: {{0, 20}, {1024, 44}}; .bounds: {{0, 0}, {1024, 44}}
-[XYZViewController viewDidLayoutSubviews] self.navigationBar: .frame: {{0, 0}, {1366, 44}}; .bounds: {{0, 0}, {1366, 44}}

-[XYZViewController viewWillLayoutSubviews] self.navigationBar: .frame: {{0, 0}, {1366, 44}}; .bounds: {{0, 0}, {1366, 44}}
-[XYZViewController viewDidLayoutSubviews] self.navigationBar: .frame: {{0, 0}, {1366, 44}}; .bounds: {{0, 0}, {1366, 44}}

-[XYZViewController viewWillAppear:] self.navigationBar: .frame: {{0, 0}, {1366, 44}}; .bounds: {{0, 0}, {1366, 44}}

-[XYZViewController viewWillLayoutSubviews] self.navigationBar: .frame: {{0, 0}, {1366, 44}}; .bounds: {{0, 0}, {1366, 44}}
-[XYZViewController viewDidLayoutSubviews] self.navigationBar: .frame: {{0, 20}, {1366, 44}}; .bounds: {{0, 0}, {1366, 44}}

-[XYZViewController viewWillLayoutSubviews] self.navigationBar: .frame: {{0, 20}, {1366, 44}}; .bounds: {{0, 0}, {1366, 44}}
-[XYZViewController viewDidLayoutSubviews] self.navigationBar: .frame: {{0, 20}, {1366, 44}}; .bounds: {{0, 0}, {1366, 44}}

-[XYZViewController viewDidAppear:] self.navigationBar: .frame: {{0, 20}, {1366, 44}}; .bounds: {{0, 0}, {1366, 44}}

In this case, since the view hierarchy is different, viewWillLayoutSubviews: gets called earlier in the view controller lifecycle and the correct size has already been determined by the time viewWillAppear: is invoked. 在这种情况下,由于视图层次结构不同, viewWillLayoutSubviews:在视图控制器生命周期中较早调用,并且已调用viewWillAppear:时间的正确大小。 But as you can see, this really depends on your view hierarchy - so I would recommend that you confirm your view hierarchy and then determine the best location to add your resolution-dependent code. 但正如您所看到的,这实际上取决于您的视图层次结构 - 因此我建议您确认视图层次结构,然后确定添加与分辨率相关的代码的最佳位置。

If you hard code the frame of any UI elements due to some reasons, you may have to change it for upcoming iPad pro. 如果由于某些原因对任何UI元素的框架进行硬编码,则可能需要为即将推出的iPad专业版更改它。 Because, it has a different screen size (in points) altogether. 因为,它具有不同的屏幕尺寸(以点为单位)。

If you use auto layout and dynamic frames (eg self.view.bounds.size.width), it should just work fine I guess. 如果你使用自动布局和动态帧(例如self.view.bounds.size.width),我猜它应该工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM