How to create a fixed navigation bar iOS Swift

放肆的年华 提交于 2019-12-13 18:43:43

问题


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:

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

I also tried adding a scroll-view.

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

Thanks.


回答1:


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.

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.

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:



来源:https://stackoverflow.com/questions/33480298/how-to-create-a-fixed-navigation-bar-ios-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!