如何创建一个固定的导航栏的iOS斯威夫特 [英] How to create a fixed navigation bar iOS Swift

查看:168
本文介绍了如何创建一个固定的导航栏的iOS斯威夫特的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个固定的头不与tableViewCells或其他内容,我有滚动。头应留在原地的固定的,就像在大多数iOS应用。

I want to create a fixed header that doesn't scroll with tableViewCells, or other content that I have. The header should stay in place fixed, just like in most iOS apps.

下面是我面临这个问题的图片:

Here is the image of the issue I'm facing:

在这里输入的形象描述

我想在一个NavigationController&安培嵌入它;一个TabViewController。没有工作。

I tried embedding it in a NavigationController & a TabViewController. That didn't work.

我也尝试添加滚动视图。

I also tried adding a scroll-view.

我提到了这个链接,但它是过时的,并没有帮助:<一href=\"http://stackoverflow.com/questions/9704508/how-iphone-facebook-app-make-the-navigation-bar-fixed\">how iPhone Facebook应用程序使导航栏固定

I referred to this link but it's outdated and didn't help: how iphone facebook app make the navigation bar fixed

感谢。

推荐答案

我真的建议,直到你看着办吧与导航控制器鬼混,这真是这种情况的最好的方法。如果你嵌入了,我会找你的看法与属性检查器中,使已启用需要确保一切。

I'd really recommend fooling around with the Navigation controller until you figure it out, it's really the best method for this. If you've embedded it, I'd check out your view with the Attributes inspector, to make sure everything needed is enabled.

但是,我以前用过的另一种方式。创建一个新的ViewController,创造它内部的两种观点。一会是您的 FakeNavBar ,然后其他的将是一个集装箱/ TableView中这会抓住你的数据。

HOWEVER, there is another way I've used before. Create a new ViewController, and create two views inside of it. One will be your FakeNavBar, and the other will be a container/TableView that'll hold your data.

一旦你加入这两个到新的VC,只是设置它们正常,宾果!
这样做的一个技巧,就是NavBar是典型的64点高,所以你的假条会是这样的:

Once you've added both these to your new VC, just set them up normally, and bingo! One tip for this, is that NavBar is typically 64 points high, so your fake bar will be something like this:

fakeNavBar.frame = CGRectMake(0, 0, theWidth, 64)
tableView.frame = CGRectMake(0, 64, theWidth, theHeight-64)

和您的视图层次结构看起来就像这样:

And your view hierarchy will look like this:

这篇关于如何创建一个固定的导航栏的iOS斯威夫特的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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