我应该使用UIViewController还是UIView?制作自定义标签栏/导航控制器 [英] Should I use UIViewController or UIView? Making a custom tab bar/nav controller

查看:45
本文介绍了我应该使用UIViewController还是UIView?制作自定义标签栏/导航控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个同时具有底部栏和顶部栏(均已定制)的应用程序,我希望它们在应用程序的整个长度上都停留在那里,同时中间部分在视图之间切换.但是,在应用程序中的某些地方存在问题,我想使顶部栏和底部栏从屏幕上滑出并能够重新拖动.

I am making an app that has both a bottom bar and a top bar (both are customized) and i want them to stay there the entire length of the app while the middle portion switches between views. But the kicker is at some points in the app, i want to have the top bar and bottom bar slide off the screen and be able to be dragged back on.

我当时想的是拥有一个主UIViewController和三个UIView(顶部栏,中间部分和底部栏),每个UIView都从各自的文件中运行代码.有点像选项卡栏如何与导航控制器一起工作.还是我倒退了?我真的不知道...但是任何建设性的建议都可以帮助您=)

What i was thinking was to have one main UIViewController with three UIViews (top bar, middle section, and bottom bar) each running code from their own respective files. Sort of like how a Tab bar works with a nav controller. or do i have that backwards? i dont really know... but any constructive advice helps =)

我对xcode还是很陌生,并且我已经尝试了几天了,所以请不要对我太苛刻.谢谢!

Im fairly new to xcode and i've been trying to find a way for a few days now, so please dont be too harsh on me. Thanks!

推荐答案

通常,我们为每个屏幕内容"构建一个视图控制器.因此,为您提供的基本建议是,以一种使每个部分"都是其自己的视图控制器的方式来制作应用程序.这对于MVC范例尤其重要,在MVC范例中,您的业务逻辑应该位于viewControllers中,而不是视图中(仅在那里显示和交互逻辑).如果只有一个视图控制器,则通过尝试管理多个部分将使FAST变得复杂.

In general, we build one view controller for each 'screenful' of content. So the basic advice for you would be to make the app in a way where each 'section' is it's own view controller. This is especially important to the MVC paradigm, where your business logic should be in the viewControllers, not the views (just display and interaction logic there). If you had just one view controller, it would get convoluted FAST by trying to manage multiple sections.

一个好的方法可能是:将整个层次结构嵌入到导航控制器中,这将为您提供顶部栏.然后创建一个自定义的视图控制器类,该类知道如何制作您的底部栏,并使每个节成为该子类的子类.

A good route may be this: Embed the whole hierarchy in a navigation controller, which gives you the top bar. Then make a custom view controller class which knows how to make your bottom bar, and have each section subclass that.

副作用是将为每个部分VC唯一创建底部栏.如果您不希望这样做,则可以探索视图控制器的包含".基本上,这是一种构建类似于导航控制器的组件的技术,该组件可以将某些元素长时间显示在屏幕上,同时将内容"视图控制器交换为较小的屏幕部分.这不是最容易的事情,应该仔细考虑.但是,如果您确实需要在其他视图控制器来来往往时在屏幕上保持同一实例,那么这可能是正确的选择.就是说,首先考虑另一个想法(每个部分管理它自己的底栏).您可以通过促进代码重用等方式来实现它.

The side effect is that the bottom bar will be uniquely created for each section VC. If that is not desirable for you, you can explore view controller 'containment'. It is basically a technique for building components like the navigation controller, which keep certain elements onscreen for a long time, while exchanging 'content' view controllers for a smaller portion of the screen. It's not the easiest thing to do, and should be considered carefully. However, if you really need to keep the same instance of something on screen while other view controllers come and go, it may be the right way to go. That said, consider the other idea first (each section manages it's own bottom bar). You can accomplish it in a way that promotes code re-use, etc.

这篇关于我应该使用UIViewController还是UIView?制作自定义标签栏/导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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