导航不使用整个屏幕的控制器 [英] Navigation Controller that doesn't use the whole screen

查看:72
本文介绍了导航不使用整个屏幕的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个导航控制器,我不想使用整个屏幕。特别是,我想把标志图像放在屏幕顶部的栏中。不幸的是,导航控制器似乎没有这样设计。在界面构建器中,我不能占据屏幕的一部分。

I have a navigation controller which I don't want to use up the whole screen. In particular, I want to put a logo image in a bar at the top of the screen. Unfortunately, the navigation controller doesn't seem to be designed this way. In interface builder, I can't make it take up part of a screen. How would you achieve the effect of a logo image up the top and a navigation controller taking up the rest of the screen?

推荐答案

如何实现顶部的标志图像和导航控制器占据屏幕其余部分的效果?我没有这样做,但它应该是很直接。你需要一个包装视图控制器作为它的父类(让我们称之为 MyWrapperViewController ),它的视图层次结构可能最终看起来像这样:

I haven't done this myself, but it should be pretty straight-forward. You'll need a wrapper view controller to be its parent (let's call it MyWrapperViewController), and its view hierarchy might ultimately look something like this:


UIView -+ (hooked up to the view outlet in MyWrapperViewController)
        |
        +-- UIView (Your logo goes here)
        |
        +-- UIView (The "child" navigation controller's view)

标志视图可以是 UIView UIImageView ,或任何适合该内容的类。

The logo view can be a UIView, or a UIImageView, or whatever class is appropriate for the content.

MyWrapperViewController 类创建 UINavigationController 时,可以调整其视图 bounds 到小于全屏的屏幕(可能是屏幕的大小减去标志的大小,带有适当的 origin offset,因此它在标志下面),然后将其添加为子视图。

When you create a UINavigationController somewhere for your MyWrapperViewController class, you can resize its view bounds to something smaller than full-screen (perhaps the size of the screen minus the size of your logo, with an appropriate origin offset so it's below the logo), and then add it as a subview.

这篇关于导航不使用整个屏幕的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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