ios 如何以编程方式获取标签栏的高度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5388152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:19:08  来源:igfitidea点击:

How to get the height of the tabbar programmatically?

iosiphoneuikituitabbarcontrolleruitabbar

提问by Niels R.

I've found out that the height of a UITabBar is 49px (or 50px, depending on the source).

我发现 UITabBar 的高度是 49px(或 50px,取决于来源)。

Because I don't like to use too much hard-coded values in my code I was wondering if it is possible to retrieve the height of the tabbar programmatically.

因为我不喜欢在我的代码中使用太多的硬编码值,所以我想知道是否可以以编程方式检索标签栏的高度。

Kind regards,
Niels R.

亲切的问候,
尼尔斯 R.

PS: The reason I'm asking is because I have a view controller (with a list view containing text fields) that is either simply pushed by the navigationcontroller (pushViewController) or presented as a modal (presentModalViewController). As soon as the keyboard show up, the size of the view is reduced, but I have to take into account that the tabbar is only visible when the view controller is pushed and not presented as a modal.

PS:我问的原因是因为我有一个视图控制器(带有包含文本字段的列表视图),它要么由导航控制器(pushViewController)简单推送,要么作为模态(presentModalViewController)呈现。键盘一出现,视图的大小就会减小,但我必须考虑到标签栏仅在视图控制器被按下时才可见,而不是作为模态呈现。

回答by Mason

I don't totally understand your P.S., but you can do:

我不完全理解你的 PS,但你可以这样做:

tabBarController?.tabBar.frame.size.height

回答by Federico Jordan

If you want to get the standard height for the UITabBar control then you can do:

如果要获得 UITabBar 控件的标准高度,则可以执行以下操作:

    UITabBarController *tabBarController = [UITabBarController new];
    CGFloat tabBarHeight = tabBarController.tabBar.frame.size.height;

回答by Nick Ginanto

prettier

更漂亮

CGRectGetHeight(self.tabBarController.tabBar.frame)

回答by Adam Smaka

check this in your vc

在你的 vc 中检查这个

bottomLayoutGuide.length

回答by Cyril

In Swift 3, you can retrieve the height of the UITabBarwith this code below.

Swift 3,你可以检索的高度UITabBar与下面这段代码。

self.tabBarController!.tabBar.frame.size.height

self.tabBarController!.tabBar.frame.size.height

Which will return a CGFloatvalue of the height

这将返回CGFloat高度的值

回答by Hack Saw

If an object is based on UIView (which most visual elements in the library are), you can get the size from the ivar "frame".

如果对象基于 UIView(库中的大多数视觉元素都是如此),则可以从 ivar“框架”中获取大小。

回答by Jhaliya

UITabBaris inherited from UIViewas long as you mhave access to your UITabBar instance you can access and modify the frame of UITabBar,

UITabBar继承自UIView只要您可以访问您的 UITabBar 实例,您就可以访问和修改 UITabBar 的框架,

CGRect myRect = myTabBar.frame;