应用程序启动时视图的定位不同

发布于 2025-01-02 19:47:55 字数 745 浏览 2 评论 0原文

我有一个具有 UITabBarController 的应用程序,当按下不同的选项卡时,我会覆盖 viewWillAppear,获取对 tabBarController 的引用,然后调整其框架的大小。这样做的原因是某些选项卡需要屏幕的整个高度,而其他选项卡的背景位于顶部 120 像素。

我引用 tabBarcontroller 的方式是获取应用程序委托并使用其对 tabBarController 的引用来移动其位置:

MyAppDelegate *del= [UIApplication sharedApplication].delegate; del.tabBarController.view.frame = CGRectMake(0,120,320,360);

在选项卡之间切换时,此方法工作正常,但应用程序第一次加载时,它的表现有点奇怪,我无法理解为什么。我的第一个选项卡实际上有一个导航栏,然后包含一个具有 pickerView 的视图。第一次加载我的应用程序时,NavigationBar 显得低了大约 10px,但是 pickerView 仍然出现在正确的位置。我希望我可以通过在第一次调用 viewWillAppear 时以不同的方式对待事物来解决这个问题,但是如果我减少 y 位置以补偿导航栏,它会将所有内容移动到一起,包括视图中的日期选择器。

我想了解为什么应用程序在首次加载时表现不同,并希望有人可以向我解释这一点,并提供有关如何解决问题的任何想法,或者请为我指出正确的方向。我怀疑这与顶部的状态栏有关,因为它的大小与我看到的偏移量大致相同。

任何帮助将不胜感激! 谢谢

I have an app which has a UITabBarController, and when different tabs are pressed, I override viewWillAppear, get a reference to the tabBarController and then resize its frame. The reason for doing so is that some tabs require the full height of the screen, whilst other tabs have a background in the top 120pixels.

The way I am referencing the tabBarcontroller is by getting the application delegate and using its reference to the tabBarController to move its position:

MyAppDelegate *del= [UIApplication sharedApplication].delegate;
del.tabBarController.view.frame = CGRectMake(0,120,320,360);

This method works fine when switching between tabs, but the first time the application loads up it does things a bit weirdly, and I cant understand why. My first tab actually has a NavigationBar, and then contains a view which has a pickerView. The first time my application loads, the NavigationBar appears about 10px too low, however the pickerView still appears in the right position. I was hoping I could get around this by treating things differently the first time viewWillAppear is called, however if I decrease the y position to compensate for the navigation bar, it shifts everything together including the datepicker within the view.

I would like to understand why the application behaves differently when first loaded and was hoping someone could either explain this to me and with any ideas on how to solve the issue or please point me in the right direction. I suspect this has something to do with the status bar on top since that is about the same size as the offset I am seeing..

Any help would be appreciated!
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦魇绽荼蘼 2025-01-09 19:47:55

好吧,我已经弄清楚了。如果有人感兴趣,似乎在应用程序启动时,UINavigationBar 的框架具有 10 像素的任意位置。我所要做的就是将 UINavigationBar 的框架垂直位置设置回 0 像素,一切正常!任何需要执行此操作的人,代码如下:

self.navigationController.navigationBar.frame = CGRectMake(0,0,320,45)

我在 viewWillAppear 方法中调用上述行,并且一切按预期工作。

OK I've figured it out. If anyone is interested, it appears that on application startup, the UINavigationBar's frame has a y position of 10 pixels. All I had to do was set the UINavigationBar's frame vertical position back to 0 pixels and all works! Anyone needing to do this, here's the code:

self.navigationController.navigationBar.frame = CGRectMake(0,0,320,45)

I call the above line in the viewWillAppear method and all works as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文