有没有办法改变UINavigationBar在故事板的高度,而不使用UINavigationController? [英] Is there a way to change the height of a UINavigationBar in Storyboard without using a UINavigationController?

查看:228
本文介绍了有没有办法改变UINavigationBar在故事板的高度,而不使用UINavigationController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的一个视图中使用自定义 UINavigationBar ,它不是任何 UINavigationController - 层次。当我将 UINavigationBar 拖到故事板中时,它显示如下:





此栏为44像素,如果状态列不会共用这个空间。因为iOS7允许我们使用整个屏幕,包括状态栏的空间, UINavigationBar 应该是64px高,而不是44px。



如果我将视图连接到 UINavigationController 的层次结构,则它显示正确:





我在某处阅读 if > 具有属性 barPosition:设置为 UIBarPositionTopAttached ,那么该条将是64px。但是,这是 readonly -property。



我的搜索结果只显示了一些我认为工作-周围。通过在这个 UIViewController 之前添加一个无用的 UINavigationController ,我可以假装有一个层次结构,



真的没有办法有一个'rogue'没有导航控制器的帮助) UINavigationBar ,覆盖64px?
如果是这样,是否有任何有效的理由为什么?



(我不是说 UINavigationBar 默认情况下应该是64px,但在检查器中应该有一个选项)



(我也看到人们用程序化的方式解决这个问题即使这些答案有效,我仍然需要在设计时考虑这个故事板(一个缺口),我想知道的是,如果可以在故事板中设置,为什么不允许?)

解决方案

您可以设置属性 barPosition


  1. 向您添加一个委托UINavigationBar

    / li>
  2. 在委托类中实现 -positionForBar:

       - (UIBarPosition)positionForBar:(id< UIBarPositioning>)bar 
    {
    return UIBarPositionTopAttached;
    }


您的导览列也必须固定到顶部布局指南。


I want to use a custom UINavigationBar in one of my views, which is not a part of any UINavigationController-hierarchy. When I drag a UINavigationBar into Storyboard, it shows like this:

This bar is 44px, which would be enough if the status bar wouldn't share this space. Because iOS7 lets us use the entire screen, including the space for the status bar, the UINavigationBar should be 64px tall, not 44px.

If I connect the view to a UINavigationController's hierarchy, then it shows correct:

I read somewhere that if the UINavigationBar has the property barPosition: set to UIBarPositionTopAttached, then the bar would be 64px. This is, however, a readonly-property.

My search results have only shown something I consider a "work-around". By adding a useless UINavigationController before this UIViewController, I can pretend to have a hierarchy, and it will add the UINavigationBar with 64px automatically.

Is there really no way to have a 'rogue'(without the help of a navigation controller) UINavigationBar that covers 64px? If that is the case, is there any valid reasons as to why?

(I'm not saying the UINavigationBar should be 64px by default, but there should be an option for it in the inspector)

(I also see people answering with programmatic ways to solve this. Even though these answers works, I'd still have to design the storyboard with that in mind (a gap). What I want to know is if it's possible to set this in storyboard, or rather, why isn't it allowed?)

解决方案

You can set the property barPosition to UIBarPositionTopAttached another way!

  1. Add a delegate to you UINavigationBar.
  2. Implement -positionForBar: in the delegate class:

    - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
    {
        return UIBarPositionTopAttached;
    }
    

Your navigation bar's top must also be anchored to the Top Layout Guide.

这篇关于有没有办法改变UINavigationBar在故事板的高度,而不使用UINavigationController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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