![](/img/trans.png)
[英]Adding a UINavigationController in a UITabBarcontroller inside of a UINavigationController?
[英]Missing inset for buttons in UINavigationBar of UINavigationController inside UITabBarController
所以,這是交易。
我有一個UITabBarController
,其中有4個UINavigationControllers
作為他的孩子。
發生的情況是,當我以這種方式設置項目時,按鈕( 后退按鈕和可能在右側放置的按鈕 )顯示為沒有偏移(相對於屏幕邊框沒有空白)。
可以通過周圍的許多解決方案輕松解決此問題。
但是 , 在這變得有趣的是 ,當我提出模態視圖時,事情變得混亂了。 從顯示的視圖返回時,按鈕將移至預期位置。
PS:我在
UITabBarController
之外有相同的UINavigationbar
,並且沒有發生此問題。
關於這種情況為什么發生以及如何避免的任何想法?
添加一個恆定的空間,使其不會改變:
var negativeSpacer:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: self
, action: nil)
negativeSpacer.width = -5; // set the value you need
self.navigationItem.leftBarButtonItems = [...] //your left bar items
或者,您可以保存在選項卡欄中選擇的最后一個視圖控制器,例如:
func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
self.previousViewControllerIndex = // get index of your tab here
}
在關閉模態視圖后,將在您的UITabBarController上調用viewDidAppear
,您可以以編程方式選擇先前選擇的控制器
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.tabBarController.selectedIndex = previousViewControllerIndex
}
實際上,這里發生了一些奇怪的事情。
我必須手動將UINavigationController
添加為UITabBarController
的父級。 另外,我必須將其hidden
屬性設置為true
才能使其擺脫干擾。
如果有人找到更好的解決方案或在這里解釋為什么會這樣,那么正確的答案將直接傳給他/她。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.