简体   繁体   English

第一个UIView无法自动调整以适合iPhone 5或iPad

[英]First UIView not autosizing to fit iPhone 5 or iPad

I have a simple app with multiple UIViews. 我有一个带有多个UIView的简单应用程序。 I've recently begun work to create a universal app out of it get the auto-sizing and rotation of views working with the iPhone 5 and iPad. 我最近开始着手创建一个通用应用程序,以使用iPhone 5和iPad来自动调整视图大小和旋转视图。

On my very first view, the view comes up as the standard 3.5" display with a white bar beneath it on the iPhone 5 (and beside it on the iPad). There is also a toolbar attached to the bottom of the view and it appears at the place where it would be on a 3.5" display. 在我的第一个视图上,该视图为标准的3.5英寸显示屏,在iPhone 5上(在iPad上,其下方是白色条)。该视图的底部还附加了一个工具栏,在3.5英寸显示屏上的位置。 The strange thing is, when I go to another view and then return to the root view, the view is sized correctly. 奇怪的是,当我转到另一个视图然后返回到根视图时,该视图的大小正确。

I've checked my autosizing for the view - all outside and inside anchors are activated. 我已经检查了视图的自动调整大小-激活了所有外部和内部锚点。 My view mode is set to "scale to fit," and in comparison to other views, settings are the same. 我的视图模式设置为“缩放以适合”,并且与其他视图相比,设置相同。 And the strange thing is it comes up right the second time the view is displayed. 奇怪的是,第二次显示视图时它就出现了。

Any thoughts? 有什么想法吗?

I found my problem. 我发现了问题。 It was in the didFinishLaunchingWithOptions method of the application. 它在应用程序的didFinishLaunchingWithOptions方法中。

I changed: 我变了:

 UIView *rootView = self.rootViewController.view;
 CGRect rootViewFrame = rootView.frame;
 rootViewFrame.origin.y +=[UIApplication sharedApplication].statusBarFrame.size.height;

to

 UIView *rootView = self.rootViewController.view;
 CGRect rootViewFrame = [[UIScreen mainScreen] applicationFrame];

The app was picking up the hard coded size of the view from the XIB when the view first loaded; 首次加载视图时,该应用正在从XIB获取视图的硬编码大小; now I just fit it within the application frame. 现在,我将其放入应用程序框架中。

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

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