[英]UIView's height not taking into account the Navigation Bar when using Storyboards
I've seen questions that look like this but the misunderstanding of people asking them was that they checked their UIView
's height on viewDidLoad:
and when they checked it again on viewDidAppear:
the result was as expected. 我见过类似的问题,但是人们问他们的误解是他们在
viewDidLoad:
上检查了UIView
的高度,而在viewDidAppear:
再次检查了它的高度viewDidAppear:
结果是预期的。
So I'm checking (and most importantly using the value for some animations) and the height of the view I get doesn't take into account the UINavigationBar
present. 因此,我正在检查(最重要的是使用某些动画的值),并且所获得的视图高度未考虑存在的
UINavigationBar
。 The thing to note is that I'm using a UIStoryboard
and autolayout
. 需要注意的是,我正在使用
UIStoryboard
和autolayout
。
Any hints of why I'm getting the height of the whole screen and how can I get the correct value? 为什么我要获得整个屏幕的高度以及如何获得正确的值?
Thank you 谢谢
Try setting the translucency of your navigation bar to NO in your storyboard file and get the frame of the view from the view's -(void)didLayoutSubviews
method or the view controller's -(void)viewDidLayoutSubviews
method. 尝试在情节
-(void)didLayoutSubviews
文件中将导航栏的透明度设置为NO,然后从视图的-(void)didLayoutSubviews
方法或视图控制器的-(void)viewDidLayoutSubviews
方法获取视图的框架。 These get called when a view's frames have been updated and the view's layout is finalised (and on refreshes, so you might want to put in a check for the first run). 当视图的框架已更新且视图的布局已完成(以及刷新时,因此您可能需要检查一下首次运行)时,将调用这些方法。
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.