将UINavigationController的工具栏移到顶部,使其位于导航栏下方 [英] Move UINavigationController's toolbar to the top to lie underneath navigation bar

查看:160
本文介绍了将UINavigationController的工具栏移到顶部,使其位于导航栏下方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建UINavigationController时,可以通过setToolbarHidden:animated:(或通过选中Interface Builder中的Shows Toolbar)来显示其默认隐藏的UIToolbar.这将导致工具栏出现在屏幕底部,并且该工具栏在推入和弹出导航堆栈上的视图控制器之间持续存在.正是我需要的,除了我需要工具栏位于屏幕的 top 处.看来这正是Apple使用iTunes应用程序所做的事情:

When you create a UINavigationController, you can reveal its default hidden UIToolbar via setToolbarHidden:animated: (or by checking Shows Toolbar in Interface Builder). This causes a toolbar to appear at the bottom of the screen, and this toolbar persists between pushing and popping of view controllers on the navigation stack. That is exactly what I need, except I need the toolbar to be located at the top of the screen. It appears that's exactly what Apple has done with the iTunes app:

如何将UINavigationController的工具栏移至顶部,使其位于导航栏下方而不是底部?

How can one move UINavigationController's toolbar to the top to lie underneath the navigation bar instead of at the bottom?

在将self.navigationController?.toolbardelegate设置为self之后,我尝试实现UIToolbarDelegate,覆盖positionForBar:并返回UIBarPosition.TopAttachedUIBarPosition.Top,但这甚至没有调用委托方法,因此它不会更改栏的位置.

I've tried to implement the UIToolbarDelegate, override positionForBar:, and return UIBarPosition.TopAttached or UIBarPosition.Top after setting the delegate of self.navigationController?.toolbar to self, but this did not even call the delegate method therefore it didn't change the bar position.

请注意,我需要在导航之间保留工具栏,因此不能简单地将工具栏添加到视图控制器并将其放置在导航栏下方.

Note that I need the toolbar to be preserved between navigation, so I can't simply add a toolbar to a view controller and position it under the nav bar.

推荐答案

您可以创建的不是UITableViewController而是UIViewController.在UIViewController的视图中,将UIToolBar放在NavigationBar和UITableView下面.将所有必需的UITableView列表委托给UIViewController,仅此而已. 为什么要使用UIViewController而不是UITableViewController?因为tableView将没有静态position元素.您应该有一些不包含ScrollView的东西.在这种情况下,只有UIView.另外,您可能会对tableView的UIScrollView进行了一些修改,但是我认为所描述的方法更加简单.

You may create not UITableViewController but UIViewController. In view of UIViewController place UIToolBar below NavigationBar and UITableView. Delegate all necessary list of UITableView to UIViewController and thats all. Why should you use UIViewController instead UITableViewController? Because tableView will not have statical positions elements. You should have something that not contains ScrollView. In this situation it is only UIView. Also you may do some hack with UIScrollView of tableView but I think described method is easer.

这篇关于将UINavigationController的工具栏移到顶部,使其位于导航栏下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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