2015-12-30 198 views

回答

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。 –

相關問題