2015-12-30 158 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。 –

相关问题