uitoolbar 的条件显示
conditional showing of uitoolbar
我有一个 UIViewController
以两种方式呈现,模态或推送到导航控制器堆栈的顶部。 UIViewController
包含一个 UITableView
和一个 UIToolbar
。当以模态方式呈现时,我需要一种为 ViewController
显示 title
的方法,因此我添加了另一个 UIToolbar
、topToolbar
。我的问题是,每当我按下 UIViewController
时,我不再需要 topToolbar
,因为 navigation tabbar
已经显示了标题。但是,当我将topToolbar
的隐藏属性设置为true
时,我的UITableView
并没有绑定到navigation tab bar
的底部并且有space 在 UITableView
和 navigation tabbar
之间,看起来不太好。我试图在 topToolbar
上调用 removeFromSuperview()
,而不是将其 hidden
属性 设置为 true
,但这没有成功,并且 topToolbar
出现在 navigation bar
下,现在我有两个 titles
而不是一个。关于如何做到这一点的任何想法?我无法添加图片,但这是我的代码,用于根据 UIViewController
是模态显示还是推送到导航堆栈顶部来操纵 UIViewController
的外观:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if itemBought != nil {
cart.items.append(itemBought!)
}
totalView.layer.borderColor = UIColor.grayColor().CGColor
totalView.layer.borderWidth = 0.5
totalLabel.text = "$" + String(format: "%.2f", cart.getTotal())
if let navBar = self.navigationController?.navigationBar {
//hide toolbar and tabbar
topToolbar.removeFromSuperview()
self.tabBarController?.tabBar.hidden = true
//hide shop button
var bottomItems: [UIBarButtonItem] = bottomToolbar.items as! [UIBarButtonItem]
if let index = find(bottomItems, shopToolbarButton) {
bottomItems.removeAtIndex(index)
}
bottomToolbar.items = bottomItems
}
}
我还应该提到我对 UITableView
有一个约束,基本上是:UItableView.top
和 Top Layout Guide.Bottom
之间的距离是 <=
到 [=18 的高度=],也就是 44。
有什么想法吗?
当您以模态方式呈现视图控制器时,为什么不将它放在 UINavigationController 中?
let navigationController = UINavigationController(rootViewController: myViewControllerInstance)
self.navigationController?.presentViewController(navigationController, animated: true, completion: { () -> Void in
//do something here when animation is complete if you want
})
我有一个 UIViewController
以两种方式呈现,模态或推送到导航控制器堆栈的顶部。 UIViewController
包含一个 UITableView
和一个 UIToolbar
。当以模态方式呈现时,我需要一种为 ViewController
显示 title
的方法,因此我添加了另一个 UIToolbar
、topToolbar
。我的问题是,每当我按下 UIViewController
时,我不再需要 topToolbar
,因为 navigation tabbar
已经显示了标题。但是,当我将topToolbar
的隐藏属性设置为true
时,我的UITableView
并没有绑定到navigation tab bar
的底部并且有space 在 UITableView
和 navigation tabbar
之间,看起来不太好。我试图在 topToolbar
上调用 removeFromSuperview()
,而不是将其 hidden
属性 设置为 true
,但这没有成功,并且 topToolbar
出现在 navigation bar
下,现在我有两个 titles
而不是一个。关于如何做到这一点的任何想法?我无法添加图片,但这是我的代码,用于根据 UIViewController
是模态显示还是推送到导航堆栈顶部来操纵 UIViewController
的外观:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if itemBought != nil {
cart.items.append(itemBought!)
}
totalView.layer.borderColor = UIColor.grayColor().CGColor
totalView.layer.borderWidth = 0.5
totalLabel.text = "$" + String(format: "%.2f", cart.getTotal())
if let navBar = self.navigationController?.navigationBar {
//hide toolbar and tabbar
topToolbar.removeFromSuperview()
self.tabBarController?.tabBar.hidden = true
//hide shop button
var bottomItems: [UIBarButtonItem] = bottomToolbar.items as! [UIBarButtonItem]
if let index = find(bottomItems, shopToolbarButton) {
bottomItems.removeAtIndex(index)
}
bottomToolbar.items = bottomItems
}
}
我还应该提到我对 UITableView
有一个约束,基本上是:UItableView.top
和 Top Layout Guide.Bottom
之间的距离是 <=
到 [=18 的高度=],也就是 44。
有什么想法吗?
当您以模态方式呈现视图控制器时,为什么不将它放在 UINavigationController 中?
let navigationController = UINavigationController(rootViewController: myViewControllerInstance)
self.navigationController?.presentViewController(navigationController, animated: true, completion: { () -> Void in
//do something here when animation is complete if you want
})