Mat*_*ves 47 iphone cocoa-touch uiscrollview uikit uitabbar
我正在编写一个UITabBar用于部分导航的应用程序.我也用它UIScrollView来呈现比屏幕通常可以处理的更多信息.因此,我需要设置滚动视图以考虑UITabBar所有信息的高度,以便显示所有信息.
有没有办法计算height出UITabBar?
vod*_*ang 63
它是320 x 49.
如果你想测试,打开Interface Builder,添加一个UITabBar,进入标尺,你会看到它
UITabBar继承自UIVIew,因此您可以使用frame.size.height来获取高度
Vla*_*yuk 59
如果视图控制器具有作为标签栏控制器的祖先,则可以从该标签栏检索高度.
CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height;
Run Code Online (Sandbox Code Playgroud)
我希望做一些类似的事情,在ViewController视图的VISIBLE部分中居中标签.这个ViewController属于UITabBarController.
这是我用来标记我的标签的代码:
UILabel *roomLabel = [[UILabel alloc] init];
CGRect frame = [[self view] bounds];
float tabBarHeight = [[[super tabBarController] tabBar] frame].size.height;
frame.size.height -= tabBarHeight;
[roomLabel setFrame:frame];
[[self view] addSubview:roomLabel];
[roomLabel release];
Run Code Online (Sandbox Code Playgroud)
请注意,我使用[[自我视图]边界]而不是[[自我视图]框架],因为后者包括20像素顶部条作为Y偏移(抛出垂直居中).
希望这有助于某人!
顺便说一句:我使用的是iOS 4.3和XCode 4,TabBar的高度"硬编码"值对我来说仍然是49!
在Swift中:
let height = self.tabBarController?.tabBar.frame.height ?? 49.0
Run Code Online (Sandbox Code Playgroud)
依靠标签栏的实际高度,并使用幻数作为后备.
Swift 3+
let tabBarHeight = tabBarController?.tabBar.frame.size.height
print(tabBarHeight ?? "not defined")
Run Code Online (Sandbox Code Playgroud)
它应该打印49.0(CGFloat类型)
| 归档时间: |
|
| 查看次数: |
57703 次 |
| 最近记录: |