1
A
回答
1
做的是增加一個
子視圖
這裏是我的代碼,我在我的項目上雨燕2.0
let tabBarController = self.sourceViewController as TabBarController
let destinationController = self.destinationViewController as UIViewController
for view in tabBarController.placeholderView.subviews as [UIView] {
view.removeFromSuperview() // 1st remove from superview
}
// Add view to placeholder view
tabBarController.currentViewController = destinationController
tabBarController.placeholderView.addSubview(destinationController.view) // 2
// Set autoresizing mask so it fits correctly
tabBarController.placeholderView.setTranslatesAutoresizingMaskIntoConstraints(false)
destinationController.view.setTranslatesAutoresizingMaskIntoConstraints(false)
let horizontalConstraint = NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[v1]-0-|", options: .AlignAllTop, metrics: nil, views: ["v1": destinationController.view]) // 3
tabBarController.placeholderView.addConstraints(horizontalConstraint)
let verticalConstraint = NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[v1]-0-|", options: .AlignAllTop, metrics: nil, views: ["v1": destinationController.view]) // 3
tabBarController.placeholderView.addConstraints(verticalConstraint)
tabBarController.placeholderView.layoutIfNeeded() // 3
destinationController.didMoveToParentViewController(tabBarController) // 4
}
這裏測試使用
的最佳方式是我在做自定義tabbar時所指的博客,希望它能幫助你: http://swiftiostutorials.com/tutorial-custom-tabbar-storyboard/
+0
你如何獲得destinationController?我有班,但我如何獲得實例? –
+0
作爲您的UITabBarcontroller類 –
+0
對不起,這只是我沒有繼承我的實現中的TabBarController。 –
相關問題
- 1. 隱藏模式選項卡欄控制器 - 從視圖控制器中在選項卡欄控制器
- 2. 初始視圖控制器和選項卡視圖控制器
- 3. 訪問選項卡控制器視圖?
- 4. 如何將新的視圖控制器從一個選項卡推送到另一個選項卡?
- 5. iOS選項卡在視圖中但不是選項卡欄控制器。
- 6. iOS如何實現沒有選項卡欄項目的選項卡欄視圖控制器?
- 7. 在多個視圖控制器共享一個UIPicker(標籤欄控制器選項卡)
- 8. 如何在所有UIViewControllers中顯示選項卡欄控制器
- 9. 在選項卡控制器中選擇了兩個選項卡
- 10. 在選項卡欄控制器中搜索導航控制器
- 11. 推到另一選項卡的視圖控制器
- 12. 更改標籤欄中選項卡的目標視圖控制器
- 13. 如何設置標籤欄控制器的默認選項卡
- 14. 選項卡式控制器圖標 - 無法顯示png
- 15. 選項卡欄控制器:在切換視圖之前執行代碼
- 16. 標籤欄控制器如何從一個視圖控制器切換到另一個視圖控制器並保留標籤欄?
- 17. 選項卡中帶有導航控制器的選項卡欄應用程序。從視圖交叉
- 18. 將選項卡欄控制器添加到UISplitViewController的根視圖?
- 19. 如何更改選項卡欄控制器中每個選項卡的外觀?
- 20. 從任何其他選項卡的視圖控制器彈出第二個選項卡的根視圖(默認)
- 21. 在選項卡式應用程序的另一個選項卡中顯示導航控制器內的視圖控制器
- 22. 使用分段控制在UITabBar選項卡中切換視圖
- 23. Ajax選項卡擴展器控制選項卡上點擊
- 24. 選項卡欄不顯示在導航控制器內的視圖控制器上
- 25. 獲取選項卡選擇事件的視圖控制器
- 26. 如何將選項卡添加到選項卡欄控制器? (iOS)
- 27. 從標籤欄控制器註銷到根視圖控制器
- 28. 切換tabbar控制器中的選項卡
- 29. monotouch導航和選項卡控制器
- 30. 控制瀏覽器選項卡索引
當前視圖控制器 – aaisataev
好的,我試過了,但它沒有顯示目標視圖中的選項卡。 –