Ios 将视图控制器添加为另一个视图控制器中的子视图
我已经读过了,但不是为我工作。我想在另一个Ios 将视图控制器添加为另一个视图控制器中的子视图,ios,swift,carbonkit,Ios,Swift,Carbonkit,我已经读过了,但不是为我工作。我想在另一个viewController中将viewController显示为子视图 这是我的密码- import UIKit import CarbonKit class ViewController: UIViewController, CarbonTabSwipeNavigationDelegate { @IBOutlet weak var containerView: UIView! override func viewDidLoad() {
viewController
中将viewController
显示为子视图
这是我的密码-
import UIKit
import CarbonKit
class ViewController: UIViewController, CarbonTabSwipeNavigationDelegate {
@IBOutlet weak var containerView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let items = ["All", "WOMEN", "MEN", "KIDS", "HOME", "CITY"]
let carbonTabSwipeNavigation = CarbonTabSwipeNavigation(items: items, delegate: self)
carbonTabSwipeNavigation.insert(intoRootViewController: self)
}
func carbonTabSwipeNavigation(_ carbonTabSwipeNavigation: CarbonTabSwipeNavigation, viewControllerAt index: UInt) -> UIViewController {
// let screen = self.storyboard?.instantiateViewController(withIdentifier: "demo") as! demo
// showSubViewContrller(subViewController: vc)
// return screen
let storyBoard = getStoryBoardByIndentifier(identifier: "All")
let vc = storyBoard.instantiateViewController(withIdentifier: "AllViewController") as! AllViewController
showSubViewContrller(subViewController: vc)
return vc
}
//Subview Controller
func showSubViewContrller(subViewController:UIViewController) {
self.addChildViewController(subViewController)
subViewController.view.frame = containerView.frame
self.containerView.addSubview(subViewController.view)
subViewController.didMove(toParentViewController: self)
}
func getStoryBoardByIndentifier(identifier:String)->UIStoryboard {
return UIStoryboard.init(name: identifier, bundle: nil)
}
}
我有一个NavigationBar
和一个tapBar
。要在容器中的视图内显示viewController
但当视图加载时,它会掩盖/隐藏选项卡栏
如何解决此问题并在我指定的容器中显示viewController
。
Project Link-我可以通过以下更改解决您的问题:
将此方法替换为carbonTabSwipeNavigation.insert(introotviewcontroller:self)
为carbonTabSwipeNavigation.insert(introotviewcontroller:self和targetview:containerView)
注意:为SuperView非安全区域提供UITaBar
底部约束:
在ViewController中添加以下代码:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
tabbar.invalidateIntrinsicContentSize()
}
运行此操作后,您将uitabar
:
我可以通过以下更改解决您的问题:
将此方法替换为carbonTabSwipeNavigation.insert(introotviewcontroller:self)
为carbonTabSwipeNavigation.insert(introotviewcontroller:self和targetview:containerView)
注意:为SuperView非安全区域提供UITaBar
底部约束:
在ViewController中添加以下代码:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
tabbar.invalidateIntrinsicContentSize()
}
运行此操作后,您将uitabar
:
@MdRashedPervez为您工作?非常感谢您的帮助。它对我有用:)。但另一个问题出现了——当tabBar视图出现在容器上时,段头就消失了。在这方面你能帮我吗我已经检查过Tabbar没有引起问题。看起来carbonTabSwipeNavigation.insert(插入rootviewcontroller:self和targetview:containerView)
@MdRashedPervez为您工作了?非常感谢您的帮助。它对我有用:)。但另一个问题出现了——当tabBar视图出现在容器上时,段头就消失了。在这方面你能帮我吗我已经检查过Tabbar没有引起问题。看起来carbonTabSwipeNavigation.insert(插入rootviewcontroller:self和targetview:containerView)有问题。