如何考虑其他 UIElement 的高度来检索可用高度?

发布于 2024-12-03 01:16:38 字数 345 浏览 5 评论 0原文

我怎样才能获得可用高度?

我尝试过:

NSLog(@"%f", [self bounds].size.height);
NSLog(@"%f", [self frame].size.height);
NSLog(@"%f", [[UIScreen mainScreen] bounds].size.height);

我总是得到屏幕的高度。 但实际高度要小一些。信息栏在顶部+导航栏,高度更小。

编辑: 我需要以编程方式检索高度。那就是如果有一个 TabBar 并且我的视图并不总是在 NavBar-Controller 中。也许没有导航栏。

How can i get the available height?

I tried:

NSLog(@"%f", [self bounds].size.height);
NSLog(@"%f", [self frame].size.height);
NSLog(@"%f", [[UIScreen mainScreen] bounds].size.height);

I get always the screen's height.
But the actual height is smaller. With Informationbar on the top + Nav-Bar, the height is smaller.

EDIT:
I need to retrieve the height programmatically. Thats if there is a TabBar and my View is not always in a NavBar-Controller. Maybe there is no NavBar.

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

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

发布评论

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

评论(2

绅士风度i 2024-12-10 01:16:38

导航栏的预定义高度为 44,您永远无法更改。通过信息栏,我认为你的意思是状态栏,其固定高度为20。iPhone屏幕的总高度 480。你进行计算...:)

但是,如果您想要这样的屏幕的高度,那么在笔尖中总是模拟状态栏和导航栏,然后拥有所有的 UI 元素。之后,当你要做的时候

self.view.frame.size.height

你会得到你的视图的高度

Navigation bar has a predefined height of 44 which you can never change. And by information bar, i think u mean the status bar which has a fixed height of 20. Total height of iPhone screen is 480. U do the calculations... :)

However, if you want the height of such a screen then in the nib always have status bar and navigation bar simulated and then have all the UI elements for that. After that, when you'll do

self.view.frame.size.height

you'll get the height of your view

莳間冲淡了誓言ζ 2024-12-10 01:16:38
self.view.frame.size.height;

或者

float theHeight = // one of the methods you posted
theHeight -= 44; // for nav bar
theHeight -= 20; // for status bar
self.view.frame.size.height;

OR

float theHeight = // one of the methods you posted
theHeight -= 44; // for nav bar
theHeight -= 20; // for status bar
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文