以编程方式获取导航栏的高度 [英] Programmatically get height of navigation bar

查看:64
本文介绍了以编程方式获取导航栏的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道更多视图控制器(导航栏)的存在将UIView按其高度向下推.我也知道这个高度= 44px.我还发现,这种下推保持了[self.view].frame.origin.y = 0.

I know that the presence of the more view controller (navigation bar) pushes down the UIView by its height. I also know that this height = 44px. I have also discovered that this push down maintains the [self.view].frame.origin.y = 0.

那么,除了将其设置为常数之外,我如何确定此导航栏的高度?

So how do I determine the height of this navigation bar, other than just setting it to a constant?

或者,较短的版本,如何确定我的UIView显示在导航栏的顶部?

Or, shorter version, how do I determine that my UIView is showing with the navigation bar on top?

灯泡开始点亮.不幸的是,我还没有发现一种统一的方法来纠正此问题,如下所述.

The light bulb started to come on. Unfortunately, I have not discovered a uniform way to correct the problem, as described below.

我相信我的整个问题都集中在我的自动调整大小蒙版上.我得出结论的理由是,无论是否使用UIWebView,都存在相同的症状.症状是肖像"的一切都是桃红色的.对于风景",最底部的UIButton在TabBar后面弹出.

I believe that my whole problem centers on my autoresizingMasks. And the reason I have concluded that is the same symptoms exist, with or without a UIWebView. And that symptom is that everything is peachy for Portrait. For Landscape, the bottom-most UIButton pops down behind the TabBar.

例如,在一个UIView上,从上到下:

For example, on one UIView, I have, from top to bottom:

UIView –既设置了弹簧(默认情况),也没有支柱

UIView – both springs set (default case) and no struts

UIScrollView-如果设置了两个弹簧,并清除其他所有内容(如UIView),则UIButton会侵入紧接其上方的对象.如果我清除所有内容,则UIButton可以,但是最顶部的内容隐藏在StatusBar的后面.仅设置顶部的支柱,UIButton向下弹出在选项卡栏的后面.

UIScrollView - If I set the two springs, and clear everything else (like the UIView), then the UIButton intrudes on the object immediately above it. If I clear everything, then UIButton is OK, but the stuff at the very top hides behind the StatusBar Setting only the top strut, the UIButton pops down behind the Tab Bar.

UILabel和UIImage垂直向下–顶部支撑杆设置,在其他位置都灵活

UILabel and UIImage next vertically – top strut set, flexible everywhere else

只需为拥有UIWebView的少数人完成图片:

Just to complete the picture for the few that have a UIWebView:

UIWebView-支撑杆:上,左,右弹簧:两者

UIWebView - Struts: top, left, right Springs: both

UIButton –没有设置,即在任何地方都灵活

UIButton – nothing set, i.e., flexible everywhere

尽管我的灯泡昏暗,但似乎还是有希望的.

Although my light bulb is dim, there appears to be hope.

请多多包涵,因为我需要的空间比简短回复的注释还要多.

Please bear with me because I needed more room than that provided for a short reply comment.

感谢您尝试了解我真正在钓鱼的目的...所以去了.

Thanks for trying to understand what I am really fishing for ... so here goes.

1)每个UIViewController(一个TabBar应用)都有一个UIImage,一些文本以及顶部的内容.另一个共同点是底部的UIButton.在某些UIViewController上,我在UIButton上方有一个UIWebView.

1) Each UIViewController (a TabBar app) has a UIImage, some text and whatever on top. Another common denominator is a UIButton on the bottom. On some of the UIViewControllers I have a UIWebView above the UIButton.

因此,UIImage,文本等.UIWebView(在某些情况下)UIButton

So, UIImage, text etc. UIWebView (on SOME) UIButton

围绕上述所有内容的是UIScrollView.

Surrounding all the above is a UIScrollView.

2)对于具有UIWebView的用户,其autoresizingMask如下所示:

2) For those that have a UIWebView, its autoresizingMask looks like:

   —
   |
   —

   ^
   |
   |

| — || ←----→| — || | | 伏特 UIButton的遮罩未设置任何内容,即在任何地方都可以灵活设置

|—| ←----→ |—| | | V The UIButton's mask has nothing set, i.e., flexible everywhere

在我的-viewDidLoad中,我将调用-repositionSubViews,在其中执行以下操作:

Within my -viewDidLoad, I call my -repositionSubViews within which I do the following:

如果没有UIWebView,除了将我放置在IB中的UIButton居中之外,我什么也不做.

If there is no UIWebView, I do nothing except center the UIButton that I placed with IB.

如果我确实有UIWebView,则确定其* content * Height并将其框架设置为封闭整个内容.

If I do have a UIWebView, then I determine its *content*Height and set its frame to enclose the entire content.

UIScrollView *scrollViewInsideWebView = [[webView_ subviews] lastObject];
webViewContentHeight = scrollViewInsideWebView.contentSize.height;
[webView_ setFrame:CGRectMake(webViewOriginX, webViewOriginY,
                          sameWholeViewScrollerWidth, webViewContentHeight)]

一旦这样做,我就以编程方式将UIButton向下推,以使其最终放置在UIWebView下方.

Once I do that, then I programmatically push the UIButton down so that it ends up placed below the UIWebView.

一切正常,直到我将其从纵向"旋转为横向".

Everything works, until I rotate it from Portrait to Landscape.

我在-didRotateFromInterfaceOrientation中调用我的-repositionSubViews.

I call my -repositionSubViews within my -didRotateFromInterfaceOrientation.

为什么UIWebView的内容高度不会随旋转而改变?.

Why does the content height of my UIWebView not change with rotation?.

从纵向到横向,内容宽度应扩大,内容高度应缩小.它在外观上应有尽有,但不是根据我的NSLog.

From Portrait to Landscape, the content width should expand and the content height should shrink. It does visually as it should, but not according to my NSLog.

无论如何,无论有没有UIWebView,在横向模式下,我所讨论的按钮都会在TabBar下方移动,但不会向上滚动以显示出来.当我剧烈地"滚动时,我在TabBar的后面看到它,但是随后它在TabBar的后面回退".

Anyway, with or without a UIWebView, the button I've talked about moves below the TabBar when in Landscape mode but it will not scroll up to be seen. I see it behind the TabBar when I scroll "vigorously", but then it "falls back" behind the TabBar.

最重要的是,这最后一个原因是我询问TabBar和NavigationBar的高度的原因,因为TabBar会将其自身放置在UIView的底部,而NavigationBar将UIView向下推.

Bottom line, this last is the reason I've asked about the height of the TabBar and the NavigationBar because the TabBar plants itself at the bottom of the UIView and the NavigationBar pushes the UIView down.

现在,我将在此处添加一两个评论,因为它们早些时候就没有意义了.

Now, I'm going to add a comment or two here because they wouldn't have made sense earlier.

在没有UIWebView的情况下,我保留了IB所见的一切.

With no UIWebView, I leave everything as is as seen by IB.

使用UIWebView,我将UIWebView的frame.height增加到其contentHeight,并向上调整围绕所有子视图的周围UIScrollView的高度.

With a UIWebView, I increase the UIWebView's frame.height to its contentHeight and also adjust upward the height of the surrounding UIScrollView that surrounds all the sub-views.

在那里,你有它.

推荐答案

灯泡开始点亮.不幸的是,我还没有发现一种统一的方法来纠正此问题,如下所述.

The light bulb started to come on. Unfortunately, I have not discovered a uniform way to correct the problem, as described below.

我相信我的整个问题都集中在我的自动调整大小蒙版上.我得出结论的理由是,无论是否使用UIWebView,都存在相同的症状.症状是肖像"的一切都是桃红色的.对于风景",最底部的UIButton在TabBar后面弹出.

I believe that my whole problem centers on my autoresizingMasks. And the reason I have concluded that is the same symptoms exist, with or without a UIWebView. And that symptom is that everything is peachy for Portrait. For Landscape, the bottom-most UIButton pops down behind the TabBar.

例如,在一个UIView上,从上到下:

For example, on one UIView, I have, from top to bottom:

UIView –都设置了弹簧(默认情况下)并且没有支柱

UIView – both springs set (default case) and no struts

UIScrollView - 如果我设置了两个弹簧,并清除了所有其他内容(如UIView),则UIButton会侵入其上方的对象. 如果我清除所有内容,则UIButton可以,但是最上方的内容隐藏在StatusBar的后面 仅设置顶部支柱,UIButton会在标签栏后面弹出.

UIScrollView - If I set the two springs, and clear everything else (like the UIView), then the UIButton intrudes on the object immediately above it. If I clear everything, then UIButton is OK, but the stuff at the very top hides behind the StatusBar Setting only the top strut, the UIButton pops down behind the Tab Bar.

UILabel和UIImage 垂直向下–顶部支撑杆设置,在其他位置均可灵活使用

UILabel and UIImage next vertically – top strut set, flexible everywhere else

只需为拥有UIWebView的少数人完成图片:

Just to complete the picture for the few that have a UIWebView:

UIWebView - 撑杆:上,左,右 弹簧:都

UIWebView - Struts: top, left, right Springs: both

UIButton –没有设置,即在任何地方都灵活

UIButton – nothing set, i.e., flexible everywhere

尽管我的灯泡昏暗,但似乎还是有希望的.

Although my light bulb is dim, there appears to be hope.

这篇关于以编程方式获取导航栏的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆