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

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

问题描述

当你创建一个 UINavigationController 时,你可以通过 setToolbarHidden:animated: 显示它默认隐藏的 UIToolbar (或者通过检查 Shows Toolbar in Interface建设者).这会导致一个工具栏出现在屏幕底部,并且该工具栏在导航堆栈上的视图控制器的推送和弹出之间持续存在.这正是我所需要的,除了我需要将工具栏放在屏幕的 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?

我尝试实现 UIToolbarDelegate,覆盖 positionForBar:,并返回 UIBarPosition.TopAttachedUIBarPosition.Topself.navigationController?.toolbardelegate 设置为 self 之后,但这甚至没有调用委托方法,因此它没有'不改变条形位置.

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 不会有静态位置元素.你应该有一些不包含 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天全站免登陆